select distinct name,left(date,7),(select count(name)from tab where name=t.name and left(date,7)=left(t.date,7) and isNess='1') as 旷课次数 from tab t我想这么作或许可以实现吧,不过效率不高;
select name,sum(isNess),sum(lastTime) group by name where date 在本月范围
上面得已经不错了select distinct name,sum(isNess),sum(lastTime) group by name having MONTH(date) between MONTH(getdate())-1 and MONTH(getdate())
select name,count(isNess),sum(lastTime) from 表名 where isNess=1 and monther(date)=月份 group by name 虽然下面这句也可以,但从意思上不明确 select name,sum(isNess),sum(lastTime) from 表名 group by name where isNess=1 and monther(date)=月份 sum(isNess)是求和,count(isNess)是求记录数,而这里的isNess,我认为只是一个标志,用求和的办法有些牵强
MONTH(getdate())-1 and MONTH(getdate())
虽然下面这句也可以,但从意思上不明确
select name,sum(isNess),sum(lastTime) from 表名 group by name where isNess=1 and monther(date)=月份 sum(isNess)是求和,count(isNess)是求记录数,而这里的isNess,我认为只是一个标志,用求和的办法有些牵强