旋转的钢笔 2022-12-30 17:38 采纳率: 54.5%
浏览 15
已结题

关于#mysql#的问题:mysql 如何查询实现excel 的这种效果,横向显示考试月份 examMonth,纵向显示列表数据

mysql 如何查询,最后导出实现excel 的这种效果,横向显示考试月份 examMonth,纵向显示列表数据

 SELECT * from (
         SELECT bkhcode,bkhName,examMonth,score,performanceLevel,salaryPayment from t_kh_month_old o1 
         where  status=9 
         union
         SELECT bkhcode,bkhName,examMonth,score,performanceLevel,salaryPayment from t_kh_month_new n1 
         where  status=9 
     ) t where 1=1  ORDER BY examMonth 

img

  • 写回答

2条回答 默认 最新

  • wux_labs 2022-12-30 17:53
    关注

    使用行列转换,具体要看你的查询结果来写sql。
    就像这样,望采纳,谢谢!

    SELECT * from (
             SELECT bkhcode,bkhName,sum(case when examMonth = '1月份' then score else 0 end) as "1月份",sum(case when examMonth = '2月份' then score else 0 end) as "2月份",sum(case when examMonth = '3月份' then score else 0 end) as "3月份",performanceLevel,salaryPayment from t_kh_month_old o1 
             where  status=9 group by bkhcode,bkhName,performanceLevel,salaryPayment
             union
             SELECT bkhcode,bkhName,sum(case when examMonth = '1月份' then score else 0 end) as "1月份",sum(case when examMonth = '2月份' then score else 0 end) as "2月份",sum(case when examMonth = '3月份' then score else 0 end) as "3月份",performanceLevel,salaryPayment from t_kh_month_new n1 
             where  status=9 group by bkhcode,bkhName,performanceLevel,salaryPayment
         ) t 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月31日
  • 已采纳回答 12月31日
  • 修改了问题 12月30日
  • 创建了问题 12月30日

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看