+ 2

How to use group by with a range of values in column ?

I have a column "year" in the table. I want to get the count value for the decade starting from the respective year. Example: |------------------| | Year. | |------------------| | 1931. | | 1937. | |. . | |. . | |------------------| For this I want : Start | End | Count | ---------|--------|-----------| 1931| 1940|. 5. | 1937| 1946|. 2. | . | . | . | . | . | . | . | . | . | ------------------------------|

19th Jul 2020, 2:30 PM
Digvijay Singh
Digvijay Singh - avatar
4 Respuestas
+ 1
SELECT count(*) as Count, p.Year as start, p.Year+9 as End FROM (SELECT DISTINCT Year from table_name) p JOIN table_name p1 ON p1.Year >= p.Year and p1.Year < p.Year+10 GROUP BY p.Year;
19th Jul 2020, 3:57 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
This groups by individual year not by decade. I need count value for all the value falling under (1931 and 1940) and (1937 and 1946)
19th Jul 2020, 3:31 PM
Digvijay Singh
Digvijay Singh - avatar
+ 1
Thanks alot ... 👍
19th Jul 2020, 4:06 PM
Digvijay Singh
Digvijay Singh - avatar
0
select count(*) as Count, Year from table_name where Year between '1931'and '1940' group by Year;
19th Jul 2020, 3:20 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar