L li2 Unregistered / Unconfirmed GUEST, unregistred user! 2002-05-17 #22 ORACLE 中没有CASE关键字,它有DECODE函数。 正确SQL如下: select 代码,sum(decode(类型, 0 , 数量,0) as 类型0数量, sum(decode(类型, 1, 数量 ,0 ) as 类型1数量 from tablename group by 代码
ORACLE 中没有CASE关键字,它有DECODE函数。 正确SQL如下: select 代码,sum(decode(类型, 0 , 数量,0) as 类型0数量, sum(decode(类型, 1, 数量 ,0 ) as 类型1数量 from tablename group by 代码
A ATZ Unregistered / Unconfirmed GUEST, unregistred user! 2002-05-19 #24 select 代码,sum(类型0数量),sum(类型1数量) from ( select 代码,sum(数量) 类型0数量,0 类型1数量 from tablename where 类型=0 group by 代码 union select 代码,0 类型0数量,sum(数量) 类型1数量 from tablename where 类型=1 group by 代码 ) as a group by 代码
select 代码,sum(类型0数量),sum(类型1数量) from ( select 代码,sum(数量) 类型0数量,0 类型1数量 from tablename where 类型=0 group by 代码 union select 代码,0 类型0数量,sum(数量) 类型1数量 from tablename where 类型=1 group by 代码 ) as a group by 代码
雪 雪中漫步 Unregistered / Unconfirmed GUEST, unregistred user! 2002-05-19 #25 我也用过oracle SQL如下: select 代码,sum(decode(类型, '0' ,1,'1' ,0) as 类型0数量, sum(decode(类型,'0',0,'1' ,1 ) as 类型1数量 from tablename group by 代码
我也用过oracle SQL如下: select 代码,sum(decode(类型, '0' ,1,'1' ,0) as 类型0数量, sum(decode(类型,'0',0,'1' ,1 ) as 类型1数量 from tablename group by 代码
L LiWD Unregistered / Unconfirmed GUEST, unregistred user! 2002-05-21 #26 原来Oracle中真的没有case,根据Li2的提示,终于完成了;ATZ的答案也可得到正确结果.