① sql中怎么计算两日期之间的天数
按小时统计,符合条件的为一天
小时数=select datediff(hh,'2007-10-12 9:00:00','2007-10-12 18:00:00')
② sql 统计一段时间内,有数据的天数
CreateTableT
(
idint,
datedatetime,
numint
)
insertintoTvalues(1,'2015-5-2',1)
insertintoTvalues(1,'2015-6-4',2)
insertintoTvalues(1,'2015-6-4',3)
insertintoTvalues(2,'2015-5-2',1)
insertintoTvalues(2,'2015-5-2',2)
insertintoTvalues(2,'2015-10-4',3)
--按id分组,在日期范围内统计不重复的date
Selectid,COUNT(Distinct[Date])AsCnt
FromT
Where[DATE]between'2015-05-01'and'2015-10-01'
Groupbyid
③ sql 怎么查询当前月份的所有天数
select * from 表名 where datepart(dd,时间字段)=要查询日期的天数 and
datepart(mm,时间字段)=要查询的月份
例如有个表t_cp 时间字段stime
select * from t_cp where datepart(dd,stime)=5 and datepart(mm,stime)=8
查询这个表中,8月5号的数据
④ sql按天数统计
这个应该再多一个表,逻辑清晰些.
上边的这个表用于统计每天的打卡起止时间
下边的这个表用于统计每天的小时数,和每天的工资数.
id 编号 姓名 日期 开始时间 结束时间 小时工资
1 1001 黑子 2008-05-21 11:00 12:00 20
程序在每天的最后一小时取表中属于今天的记录,用日期字段来判断第一次和最后一次(最早的时间记录和最后的时间记录),获得小时数.然后用获得的小时数*小时工资.插入到第二个表里.
id 编号 姓名 日期 工作小时 总工资
1 1001 黑子 2008-05-21 1 20
除此之外,建议再多一个用户表.
⑤ sql统计一个月一共出勤多少天
出勤天数
select * from 考勤表 where (intkqstate<7 and outkqstate<7) and 日期 between '2009-1-1' and '2009-1-31' and 员工ID=" & ID
如果不查某个人的,就不用加员工ID这个条件
未出勤天数:
select * from 考勤表 where (intkqstate>6 and outkqstate>6) and 日期 between '2009-1-1' and '2009-1-31' and 员工ID=" & ID
⑥ sql按日期时间统计次数的语句怎么写
select 卡号, count(消费日) 消费天数
from (select distinct 卡号, Day(消费时间) 消费日 from 消费明细)
GROUP by 卡号
⑦ SQL是计算两个日期相差多少天数的函数
SQL是高级的非过程化编程语言,一般针对数据库进行操作。
定义:datediff(day/month/year,startdate,enddate)
日期函数:(要返回的天数/月数/年数,开始日期,结束日期)
具体形式:
select 1,2,datediff(day,1,2) 天数 from aa