[英]case statement same column
have column that has values of total and hours inside it but I need to split the group into two columns for example有包含总计和小时值的列,但我需要将该组分成两列,例如
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
what this is returning is 2 columns but doubling it not a lining values.这返回的是 2 列,但将其加倍而不是衬里值。
Hours Total
2 null
null 20
Your table would appear to have two rows.您的表格似乎有两行。 If you want one row in the result set you need aggregation:
如果你想要结果集中的一行,你需要聚合:
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.