博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 行转列
阅读量:5128 次
发布时间:2019-06-13

本文共 1729 字,大约阅读时间需要 5 分钟。

SELECT NAME ,SUM( CASE SUBSTRING(mon, 6)  WHEN '01'  THEN sa ELSE 0 END ) AS '01月',SUM( CASE SUBSTRING(mon, 6)  WHEN '02'  THEN sa ELSE 0 END ) AS '02月',SUM( CASE SUBSTRING(mon, 6)  WHEN '03'  THEN sa ELSE 0 END ) AS '03月',mon FROM saleGROUP BY mon
SELECT   ROUND((b.num / a.num) * 100, 2) || '%' AS tpnum,  nvl (b.num, 0) AS tnum,  nvl (a.num, 0) AS num,  CAST(c.time2 AS VARCHAR (10)) AS mon FROM  (SELECT     COUNT(t.did) num,    to_char (t.ts, 'yyyy-MM') AS d   FROM    RCV_TB t   WHERE to_char (t.ts, 'yyyy') = '2019'     AND t.UNITID = '1001'   GROUP BY to_char (t.ts, 'yyyy-MM')) a   LEFT JOIN     (SELECT       *     FROM      (SELECT         COUNT(t.did) num,        to_char (t.ts, 'yyyy-MM') AS d       FROM        RCV_TB t       WHERE t.isnet = '1'       GROUP BY to_char (t.ts, 'yyyy-MM'))) b     ON a.d = b.d   RIGHT JOIN     (SELECT       '01' AS time2     FROM      DUAL     UNION    ALL     SELECT       '02' AS time2     FROM      DUAL     UNION    ALL     SELECT       '03' AS time2     FROM      DUAL     UNION    ALL     SELECT       '04' AS time2     FROM      DUAL     UNION    ALL     SELECT       '05' AS time2     FROM      DUAL     UNION    ALL     SELECT       '06' AS time2     FROM      DUAL     UNION    ALL     SELECT       '07' AS time2     FROM      DUAL     UNION    ALL     SELECT       '08' AS time2     FROM      DUAL     UNION    ALL     SELECT       '09' AS time2     FROM      DUAL     UNION    ALL     SELECT       '10' AS time2     FROM      DUAL     UNION    ALL     SELECT       '11' AS time2     FROM      DUAL     UNION    ALL     SELECT       '12' AS time2     FROM      DUAL) c     ON SUBSTR(a.d, 6, 2) = c.time2 ORDER BY c.time2

 

转载于:https://www.cnblogs.com/jentary/p/11534006.html

你可能感兴趣的文章
Java反射机制及其Class类浅析
查看>>
Postman-----如何导入和导出
查看>>
移动设备显示尺寸大全 CSS3媒体查询
查看>>
图片等比例缩放及图片上下剧中
查看>>
【转载】Linux screen 命令详解
查看>>
background-clip,background-origin
查看>>
Android 高级UI设计笔记12:ImageSwitcher图片切换器
查看>>
【Linux】ping命令详解
查看>>
对团队成员公开感谢博客
查看>>
java学习第三天
查看>>
python目录
查看>>
django+uwsgi+nginx+sqlite3部署+screen
查看>>
Andriod小型管理系统(Activity,SQLite库操作,ListView操作)(源代码下载)
查看>>
在Server上得到数据组装成HTML后导出到Excel。两种方法。
查看>>
浅谈项目需求变更管理
查看>>
经典算法系列一-快速排序
查看>>
设置java web工程中默认访问首页的几种方式
查看>>
ASP.NET MVC 拓展ViewResult实现word文档下载
查看>>
8、RDD持久化
查看>>
第二次团队冲刺--2
查看>>