有表 Table 中有两个字段 Seq int ,Reviewer int 如何写Sql语句查询出 Seq 最小值的情况下 Reviewer 重复在Reviewer 出现的次数。
目前我知道 Seq 最小用 Min(Seq)求;
Reviewer 重复在Reviewer 出现的次数 : SELECT Reviewer,COUNT(*) FROM Table GROUP BY Reviewer 求重复的次数;
但是怎么合并就不知道了
------解决方案--------------------
- SQL code
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([字段A] varchar(1),[字段B] varchar(4),[字段C] int)insert [test]select 'A','结束',3 union allselect 'A','开始',2 union allselect 'A','开始',1 union allselect 'B','结束',7 union allselect 'B','开始',6 union allselect 'B','开始',5 union allselect 'B','开始',4 union allselect 'B','开始',3 union allselect 'B','开始',2 union allselect 'B','开始',1 union allselect 'C','开始',2 union allselect 'C','开始',1 union allselect 'D','开始',3 union allselect 'D','开始',2 union allselect 'D','开始',1select MIN([字段C]) as seq,COUNT([字段B]) as timesfrom testgroup by [字段B]/*seq times3 21 13*/相同内容干嘛要发两次???