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
1. What is pip pip is a Python package management...
This article shares the specific code of Element-...
Back in the Kernel 2.6 era, a new security system...
Table of contents Preface🌟 1. API Introduction 2....
1. Find a suitable version of redis for docker Yo...
The Linux command line provides many commands to ...
When a website is maliciously requested, blacklis...
This article shares a digital clock effect implem...
MySQL allows you to create multiple indexes on a ...
For databases that have been running for a long t...
When installing a virtual machine, a prompt appea...
Table of contents introduction MySQL High Availab...
As Web developers, although we are not profession...
Newbie, record it yourself 1. Install supervisor....
Specific method: 1. Open Command Prompt 2. Enter ...