Java代码
SELECT count(DISTINCT(arect_id)) zcount ajob_dept
DATE_FORMAT(submit_date %Y%m) zsubmit_date
FROM
表名 a
WHERE
astatu =
AND arstatu =
AND ajob_dept IN ( )
GROUP BY
ajob_dept
DATE_FORMAT(submit_date %Y%m)
其中关键在于DATE_FORMAT(submit_date %Y%m)对时间年月进行了分组排序
Java代码
SELECT
zsubmit_date
MAX(CASE WHEN job_dept = THEN zcount ELSE END ) zcount
MAX(CASE WHEN job_dept = THEN zcount ELSE END ) zcount
MAX(CASE WHEN job_dept = THEN zcount ELSE END ) zcount
FROM
(
SELECT
count(DISTINCT(arect_id)) zcount ajob_dept
DATE_FORMAT(submit_date %Y%m) zsubmit_date
FROM
表名 a
WHERE
astatu =
AND arstatu =
AND ajob_dept IN ( )
GROUP BY
ajob_dept
DATE_FORMAT(submit_date %Y%m)
) q
GROUP BY
zsubmit_date
以上是mysql的列转行其中关键点是case when的用法用其来完成列转行的操作