补,问:这个SQL如何编写?

image.png

FineReport 学习2 发布于 2022-2-22 20:28
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
zsh331Lv8专家互助
发布于2022-2-22 21:17

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

——————————————

最佳回答
0
CD20160914Lv8专家互助
发布于2022-2-22 20:50

你最终要什么效果?没有明白。好待也说一下要的结果呀。

最佳回答
0
GnefnujnusLv6资深互助
发布于2022-2-22 21:06
  • 4关注人数
  • 349浏览人数
  • 最后回答于:2022-2-22 21:17
    请选择关闭问题的原因
    确定 取消
    返回顶部