简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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