求一个有关统计的语句
有一个表,数据是这样的形式:
classid	TypeName	Name	dataid	score
149	点评	屏幕	47179	146
149	点评	画面	47179	130
149	点评	屏幕	47180	105
149	点评	画面	47180	102
150	点评	性价比	47179	85
150	点评	性价比	47180	84
150	点评	接口	47180	123
150	点评	质量	47180	83
150	点评	接口	47179	111
......
现在,我用
select classid,TypeName,Name,count(*) as [count] from tb group by classid,TypeName,Name
的查询结果是:
classid	TypeName	Name	count
149	点评	屏幕	2
149	点评	画面	2
150	点评	性价比	2
150	点评	接口	2
150	点评	质量	1
现在,150的classid中3条的count不一样,我要把它找出来(可能不止3条,如果是10条,全部相同就不提,有2个以上的不同值就提出来),149的classid中2条(所有)的count都一样,就不提了
比如以上数据,就提出 150 一条
我的数据很多,如何能提出所有不相同的classid
------解决方案--------------------SQL code
;with cte as
(
select classid,TypeName,Name,count(*) as [count] from tb group by classid,TypeName,Name
)
select classid
from cte t
where exists (select 1 from cte where classid = t.classid and [count] <> t.[count])
------解决方案--------------------
SQL code
with cte as
(select classid,TypeName,Name,count(*) as [count] from tb 
 group by classid,TypeName,Name
)
select classid from cte a
 where exists(select 1 from cte where classid=a.classid and [count]<>[count])