Querying the database SELECT * FROM `student` Query results
Convert to age query statement, use the TIMESTAMPDIFF function SELECT id, name, birthday, TIMESTAMPDIFF(YEAR,student.birthday,CURDATE()) as age FROM `student` Query results
Then group them by age group SELECT GROUP_CONCAT(a.id) as ids, GROUP_CONCAT(a.name) as names, CASE WHEN a.age<18 THEN 'teen' WHEN a.age>=18 AND a.age< 40 THEN 'youth' WHEN a.age>=40 AND a.age< 60 THEN 'middle-aged' END as age, count(a.id) as count FROM (SELECT id, name, birthday, TIMESTAMPDIFF(YEAR,student.birthday,CURDATE()) as age FROM `student`) as a GROUP BY CASE WHEN a.age<18 THEN 'teen' WHEN a.age>=18 AND a.age< 40 THEN 'youth' WHEN a.age>=40 AND a.age< 60 THEN 'middle-aged' END Query results
Tips: The current time is 2020 Summarize This is the end of this article about converting MySQL date of birth to age and grouping and counting the number of people. For more related MySQL date of birth to age and grouping and counting content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Implement 24+ array methods in JavaScript by hand
>>: UDP simple server client code example
Based on the Vue image magnifier component packag...
First, take a look at Alibaba Cloud's officia...
Table of contents Vue this.$store.state.xx.xx Get...
Disclaimer: Since the project requires the use of...
Detailed explanation of MySQL instance with SSD s...
Use JS to zoom in and out when the mouse is on th...
To do MySQL performance adjustment and service st...
Building new images from existing images is done ...
We often want to find a file in Linux, but we don...
When I created a Docker container today, I accide...
Table of contents Overview Canvas API: Drawing Gr...
Today's article mainly introduces the reload ...
This blog is a work note environment: nginx versi...
In the horizontal direction, you can set the alig...
Overview In the previous chapter, we learned abou...