sql 查询

根据状态获取各个状态汇总,以下图

实现sql

select provice, 
(select count(*) from  [monitor] m where state=0  and m.provice=monitor.provice ) as m1,
(select count(*) from  [monitor] m where state=1  and m.provice=monitor.provice) as m2,
(select count(*) from  [monitor] m where state=2  and m.provice=monitor.provice) as m3,
(select count(*) from  [monitor] m where state=3  and m.provice=monitor.provice) as m4
from [dbo].[monitor]  group by provice
相关文章
相关标签/搜索