[英]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.