首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

查询条件聚合?该怎么解决

2011-12-31 
查询条件聚合???姓名出勤时间张1周1王2周2赵5周3张1周7王2周6赵5周1张1周5王2周1赵5周3要求只有周1到周7都

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

张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

热点排行