怎么用一条sql语句查出一个表中字段YT分别为'油'和为'才'的个数
sql
------解决方案--------------------------------------------------------
select sum(case when yt='油' then 1 else 0 end)[油],sum(case when yt='才' then 1 else 0 end)[才] from tb
------解决方案--------------------------------------------------------
正解
------解决方案--------------------------------------------------------
或者decode
select sum(decode(yt,'油',1,0)) "油,
sum(decode(yt,'才',1,0)) "才"
from tb
------解决方案--------------------------------------------------------
掉了个双引号 "油 → "油"