如何寫出這樣需求的sql?
table a
id name groupid state type type2
1 model1 1 1 a A
2 model2 1 1 a A
3 model3 1 1 a B
4 model4 1 0 a B
5 model5 2 1 b A
6 model6 2 0 b A
7 model7 2 0 b B
8 model8 2 1 b B
9 model9 2 1 b B
需要顯示根據groupid,和state=1來做條件的結果:
type count
a 3
b 3
這樣的sql該如何寫?
謝謝各位啦!!
------解决方案--------------------select type ,count(1) as [count]
from a
where state =1
group by type
------解决方案--------------------select type,count(type) from a where state=1 group by a order by groupid
------解决方案-------------------- select type,count=count(*) from a
where state =1
group by type
------解决方案--------------------(@_@)!