Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- name varchar(20),
- age int
- )
- INSERT INTO person VALUES
- ('temp',9),
- ('temp',10),
- ('temp',53),
- ('temp',23),
- ('temp',12),
- ('temp',42),
- ('temp',25),
- ('temp',28),
- ('temp',52),
- ('temp',60),
- ('temp',72),
- ('temp',61),
- ('temp',58),
- ('temp',73),
- ('temp',12),
- ('temp',42)
- DECLARE @low int = 0
- DECLARE @t TABLE(ageRange varchar(10), amount int)
- WHILE @low < (SELECT MAX(age) FROM person)
- BEGIN
- INSERT INTO @t
- SELECT CAST(@low AS CHAR(2))+' - '+CAST(@low+9 AS char(2)), COUNT(*)
- FROM person
- WHERE age BETWEEN @low AND @low+9
- SET @low = @low+10
- END
- SELECT * FROM @t WHERE amount > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement