日期:2014-05-19  浏览次数:20515 次

查询条件聚合???
姓名         出勤时间

张1               周1
王2             周2
赵5               周3
张1             周7
王2             周6
赵5             周1
张1             周5
王2             周1
赵5             周3

要求只有周1到周7都有出勤记录的才罗列统计出来
姓名         出勤时间累计
张1               周1+周2...+周7
王2             周1+周2...+周7


------解决方案--------------------
select 姓名,出勤时间累计= '周1+周2...+周7 ' from tb group by 姓名 having count(出勤时间)=7
------解决方案--------------------
select 姓名,[出勤时间]=sum(出勤时间) from ta group by 姓名 having count(distinct 出勤时间)=7

------解决方案--------------------
加个distinct

select 姓名,出勤时间累计= '周1+周2...+周7 ' from tb group by 姓名 having count(distinct(出勤时间))=7