![我需要统计各个layerid对应的U、A是多少。比如
HYD_NET_LN U 5 A 10
HYD_VAL_PT U 8 A 25
应该如何写
][1]
PHP中文网2017-05-18 10:55:38
简单点,不知道这样可不可以。
SELECT layerid,ChangeMold,COUNT(ChangeMold) FROM table_name
GROUP BY layerid,ChangeMold
巴扎黑2017-05-18 10:55:38
SELECT
layerid,
sum(case when changeMold='U' then 1 else 0 end) changeMold_U,
sum(case when changeMold='A' then 1 else 0 end) changeMold_A
FROM table_name
GROUP BY layerid;
天蓬老师2017-05-18 10:55:38
select layerid,changeMold,count(*) as num from TABLE where layerid in (select layerid from TABLE group by layerid) group by changeMold; 这条sql的性能很不好