使用有条件的聚集地
select NAMA,max(case when jam=1 then status end) as jam1,max(case when jam=2 then status end) as jam2,max(case when jam=3 then status end) as jam3
from FL_TEST group by NAMA
或者您可以使用数据透视
SELECT *
FROM FL_TEST
PIVOT (
MAX(status) as JAM FOR jam IN (1,2,3)
);
,
您可以使用Conditional Aggregation
:
select nama,max( case when jam = 1 then status end ) as jam1,max( case when jam = 2 then status end ) as jam2,max( case when jam = 3 then status end ) as jam3
from tab
group by nama
或pivot
:
select *
from tab
pivot(
max(value) for field in ( 1 as "Jam1",2 as "Jam2",3 as "Jam3" ) )
Demo
本文链接:https://www.f2er.com/3161511.html