+ 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. | . | . | . | . | . | . | . | . | . | ------------------------------|
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;
+ 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)
+ 1
Thanks alot ... 👍
0
select count(*) as Count, Year from table_name where Year between '1931'and '1940' group by Year;