NutzCN Logo
问答 看这个日志里面的sql,order by 前少个空格
发布于 2642天前 作者 qq_1d84c364 1526 次浏览 复制 上一个帖子 下一个帖子
标签:
[DEBUG] 14:20:03.472 
  For example:> "SELECT a.id, a.name, a.createTime,
IF((FROM_UNIXTIME(a.beginTime,'%Y%m%d')= date_format(now(),'%Y%m%d')) or a.beginTime is NULL, 1,0) isToday,
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') > date_format(now(),'%Y%m%d'), 1,0) isFuture,
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') < date_format(now(),'%Y%m%d'), 1,0) isover,
IF(b.taskId is NULL, 0, 1) isEnd
from ttask a LEFT JOIN ttaskendusermap b on a.id = b.taskId and b.loginUserId = 57
where a.isLoopTemplate=0 and a.taskType = 1
and a.createUserId = 57
and a.companyId = 8
and a.name like '%%'
and b.taskId is
 nullorder by a.id desc"

我的自定义sql文件如下:

/*getDayTaskList*/
SELECT a.id, a.name, a.createTime,
IF((FROM_UNIXTIME(a.beginTime,'%Y%m%d')= date_format(now(),'%Y%m%d')) or a.beginTime is NULL, 1,0) isToday, 
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') > date_format(now(),'%Y%m%d'), 1,0) isFuture, 
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') < date_format(now(),'%Y%m%d'), 1,0) isover, 
	IF(b.taskId is NULL, 0, 1) isEnd 
	from ttask a LEFT JOIN ttaskendusermap b on a.id = b.taskId and b.loginUserId = @createUserId
	where a.isLoopTemplate=0 and a.taskType = 1
 	and a.createUserId = @createUserId
	and a.companyId = @companyId
		<%if(has("beginTime")){%>
  			and a.beginTime >= @beginTime
  		<%}%>
  		<%if(has("endTime")){%>
  			and a.beginTime <= @endTime
  		<%}%>
  		<%if(!isEmpty(term)){%>
  			and a.name like @term
  		<%}%>
  		<%if(has("labelId")){%>
  			and a.id in (select b.taskId from ttasklabelmap b where b.labelId=@labelId)
  			and (a.createUserId=@createUserId 
  			or a.id in (select taskid from ttaskemployeemap  where employeeId =@currentEmployeeId)
  			or a.id in (select taskid from ttasklabelmap where labelid in (select labelid from tcommonlabelusermap where loginuserid =@createUserId))
  			 )
  		<%}%>
  		<%if(has("isend") && isend.~size == 1){%>
			and b.taskId is
			<%for(item in isend){%>
			 <%if(item == 1){%>not<%}%> null 
			<%}%>
		<%}%>
      order by a.id desc
9 回复

哦? 模板? beginTime有值的时候也会吗?

SELECT a.id, a.name, a.createTime,
IF((FROM_UNIXTIME(a.beginTime,'%Y%m%d')= date_format(now(),'%Y%m%d')) or a.beginTime is NULL, 1,0) isToday,
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') > date_format(now(),'%Y%m%d'), 1,0) isFuture,
IF(a.beginTime is not null and FROM_UNIXTIME(a.beginTime,'%Y%m%d') < date_format(now(),'%Y%m%d'), 1,0) isover,
IF(b.taskId is NULL, 0, 1) isEnd
from ttask a LEFT JOIN ttaskendusermap b on a.id = b.taskId and b.loginUserId = 57
where a.isLoopTemplate=0 and a.taskType = 1
and a.createUserId = 57
and a.companyId = 8
and a.beginTime >= 1504454400
and a.name like '%%'
and b.taskId is
nullorder by a.id desc

and a.beginTime >= 1504454400没问题

我试了一下, 好像是for循环才会这样

如果不用for有办法吗 我的list可能就一个值

或者order如何在代码里指定

试了一下, 临时办法, 强制加个空格

      ${1==1 ? ' ':' '}
      order by a.id desc

嗯,就先这样吧

看来要加点帮助方法

添加回复
请先登陆
回到顶部