晕,你跑到ORACLE来问问题,结果你的数据库是MS SQL 改成这样 select count(*) as tot,sum(case when sex='男' then 1 else 0 end)/count(*) as m_rate, sum(case when sex='女' then 1 else 0 end)/count(*) as f_rate from a
select round(100*t1.tt1/t2.tt2,2) || '%',round(100*(t2.tt2-t1.tt1)/t2.tt2,2) || '%' from (select count(*) tt1 from test where sex='男') t1, (select count(*) tt2 from test) t2
name sex
张三 男
李四 女
select count(*) tot,sum(decode(sex,'男',1,0))/count(*) m_rate,
sum(decode(sex,'女',1,0))/count(*) f_rate
from a
运行错误如下:
服务器: 消息 195,级别 15,状态 10,行 2
'decode' 不是可以识别的 函数名。
改成这样
select count(*) as tot,sum(case when sex='男' then 1 else 0 end)/count(*) as m_rate,
sum(case when sex='女' then 1 else 0 end)/count(*) as f_rate
from a
from
(select count(*) tt1 from test where sex='男') t1,
(select count(*) tt2 from test) t2
你们都是牛人~