As shown below: SELECT count(DISTINCT(a.rect_id)) zcount, a.job_dept, DATE_FORMAT(submit_date, '%Y-%m') zsubmit_date FROM Table Namea WHERE a.status = 3 AND a.rstatu = 2 AND a.job_dept IN ('19', '20', '21') GROUP BY a.job_dept, DATE_FORMAT(submit_date, '%Y-%m') The key is that DATE_FORMAT (submit_date, '%Y-%m') groups and sorts the time, year and month. SELECT zsubmit_date, MAX(CASE WHEN job_dept = '19' THEN zcount ELSE 0 END ) 19zcount, MAX(CASE WHEN job_dept = '20' THEN zcount ELSE 0 END ) 20zcount, MAX(CASE WHEN job_dept = '21' THEN zcount ELSE 0 END ) 21zcount FROM ( SELECT count(DISTINCT(a.rect_id)) zcount, a.job_dept, DATE_FORMAT(submit_date, '%Y-%m') zsubmit_date FROM Table Namea WHERE a.status = 3 AND a.rstatu = 2 AND a.job_dept IN ('19', '20', '21') GROUP BY a.job_dept, DATE_FORMAT(submit_date, '%Y-%m') ) q GROUP BY zsubmit_date The above MySQL column to row conversion and year-month grouping example is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of nginx reverse proxy webSocket configuration
>>: Implementation of k8s node rejoining the master cluster
In Linux C/C++, thread-level operations are usual...
Preface Recently, due to work reasons, I was work...
Table of contents 1. Common mistakes made by begi...
In the previous article, we explained how nginx r...
Recently, the company has put forward a requireme...
There are always some problems when configuring n...
CSS3 can change the color of pictures. From now o...
Before reading this article, I hope you have a pr...
Since the network requests initiated by native js...
There is a picture in a big box. When you put the...
Table of contents Install Dependencies Configurat...
Table of contents What is maintainable code? Code...
MYSQL commonly used query commands: mysql> sel...
MySQL Performance Optimization MySQL is widely us...
Preface This article mainly introduces how to sta...