SELECT
rkfs,
sum(case when ck ="DFW" then piece else 0 end) as piece,
sum(case when ck ="DFW" then cmb else 0 end) as cmb,
sum(case when ck ="PHX" then piece else 0 end) as piece1,
sum(case when ck ="PHX" then cmb else 0 end) as cmb1
FROM
test
GROUP BY
rkfs
union all
SELECT
hj as rkfs,
sum(case when ck ="DFW" then piece else 0 end) as piece,
sum(case when ck ="DFW" then cmb else 0 end) as cmb,
sum(case when ck ="PHX" then piece else 0 end) as piece1,
sum(case when ck ="PHX" then cmb else 0 end) as cmb1
FROM
test
——————————————