查询时间的格式问题

这里根据“起始时间”查询请假统计(事假病假等),查询的结果不准确,是不是因为时间的格式,应该怎么改?


select 请假人,单位,count(*) as 请假次数,sum(请假天数) as 请假天数 

,(select count(*) from 请假申请 a 

where 请假人=请假申请.请假人 and 审核结果='通过' and

 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}

) as 通过次数

,(select count(*) from 请假申请 a 

where 请假人=请假申请.请假人 and 审核结果='驳回' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}' ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 驳回次数

,(select sum(请假天数) 

from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='事假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 事假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='病假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 病假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='婚假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 婚假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='产假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 产假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='丧假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 丧假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='会假' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 会假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='其他' and 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 其他

from 请假申请 where 起始时间>='${dateEditor0}' and 起始时间 <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}

group by 请假人,单位 


FineReport nxwzqy1 发布于 2020-9-18 08:31 (编辑于 2020-9-18 08:31)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
1
axingLv6专家互助
发布于2020-9-18 09:26(编辑于 2020-9-18 09:29)
select 
请假人,单位,
sum(请假天数) as 请假天数,
sum(case when 审核结果='通过' then 1 end) as 通过次数,
sum(case when 审核结果='驳回' then 1 end) as 驳回次数,
sum(case when 请假类型='事假' then 请假天数 end) as 事假天数,
sum(case when 请假类型='病假' then 请假天数 end) as 病假天数,
sum(case when 请假类型='婚假' then 请假天数 end) as 婚假天数,
sum(case when 请假类型='产假' then 请假天数 end) as 产假天数,
sum(case when 请假类型='丧假' then 请假天数 end) as 丧假天数,
sum(case when 请假类型='会假' then 请假天数 end) as 会假天数,
sum(case when 请假类型='其他' then 请假天数 end) as 其他假天数
from 请假申请 
where 起始时间 between '${dateEditor0}' and '${dateEditor1}'  
${if(len(单位_c)==0,""," and 单位 like '%"+单位_c+"%'")}
group by 请假人,单位


最佳回答
1
snrtuemcLv8专家互助
发布于2020-9-18 08:40(编辑于 2020-9-18 09:23)

你要把你时间都格式化一下

以MySQL数据库【精确:年月日】查询为例:

-- 控件的返回值类型:yyyy-MM-dd

select * from tabname where LEFT(日期字段,10) = '${日期控件}'

或(范围查询)

select * from tabname where LEFT(日期字段,10) between '${起始日期}' and '${截止日期}'

=============sqlserver

    SUBSTRING(日期字段,1,10)  或 LEFT(日期字段,10)

=============oracle

    substr(日期字段,1,10)




==============================================

select 请假人,单位,count(*) as 请假次数,sum(请假天数) as 请假天数

,(select count(*) from 请假申请 a

where 请假人=请假申请.请假人 and 审核结果='通过' and

 left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}

) as 通过次数

,(select count(*) from 请假申请 a

where 请假人=请假申请.请假人 and 审核结果='驳回' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}' ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 驳回次数

,(select sum(请假天数)

from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='事假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 事假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='病假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 病假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='婚假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 婚假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='产假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 产假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='丧假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 丧假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='会假' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 会假

,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='其他' and left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 其他

from 请假申请 where left(起始时间,10)>='${dateEditor0}' and left(起始时间,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}

group by 请假人,单位


  • nxwzqy1 nxwzqy1(提问者) 能给改一下吗?谢谢
    2020-09-18 08:56 
  • snrtuemc snrtuemc 回复 nxwzqy1(提问者) 看修改答案
    2020-09-18 09:23 
最佳回答
1
LarryAbbyLv5中级互助
发布于2020-9-18 08:44

select 请假人,单位,count(*) as 请假次数,sum(请假天数) as 请假天数
,(select count(*) from 请假申请 a
where 请假人=请假申请.请假人 and 审核结果='通过' and
 substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}
) as 通过次数
,(select count(*) from 请假申请 a
where 请假人=请假申请.请假人 and 审核结果='驳回' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}' ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 驳回次数
,(select sum(请假天数)
from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='事假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 事假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='病假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 病假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='婚假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 婚假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='产假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 产假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='丧假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")} ) as 丧假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='会假' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 会假
,(select sum(请假天数) from 请假申请 a where 请假人=请假申请.请假人 and 请假类型='其他' and substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}) as 其他
from 请假申请 where substr(起始时间,1,10)>='${dateEditor0}' and substr(起始时间,1,10) <='${dateEditor1}'  ${if(len(单位_c)=="",""," and 单位 like '%"+单位_c+"%'")}
group by 请假人,单位

  • nxwzqy1 nxwzqy1(提问者) 提示substr不是可以识别的内置函数名称
    2020-09-18 08:47 
  • LarryAbby LarryAbby 回复 nxwzqy1(提问者) 你是什么数据库
    2020-09-18 09:19 
  • 4关注人数
  • 432浏览人数
  • 最后回答于:2020-9-18 09:29
    请选择关闭问题的原因
    确定 取消
    返回顶部