繁体   English   中英

案例陈述同列

[英]case statement same column

有包含总计和小时值的列,但我需要将该组分成两列,例如

select 
case
when A.TYPE = 'H'

then A.Value


end as "Hours",

Case 
when A.TYPE != 'H'
then A.VALUE

end as "Total" 

from a

这返回的是 2 列,但将其加倍而不是衬里值。

Hours     Total
  2        null 
null        20

您的表格似乎有两行。 如果你想要结果集中的一行,你需要聚合:

select max(case when A.TYPE = 'H' then A.Value end) as Hours,
       max(case when A.TYPE <> 'H' then A.VALUE end) as Total
from a;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM