Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select t.range as [score range], count(*) as [number of occurences]
- from (
- select case
- when score between 0 and 9 then ' 0- 9'
- when score between 10 and 19 then '10-19'
- else '20-99' end as range
- from scores) t
- group by t.range
- select t.range as [score range], count(*) as [number of occurences]
- from (
- select case
- when score between 0 and 9 then ' 0- 9'
- when score between 10 and 19 then '10-19'
- else '20-99' end as range
- from scores) t
- group by t.range
- select t.range as [score range], count(*) as [number of occurences]
- from (
- select user_id,
- case when score >= 0 and score< 10 then '0-9'
- when score >= 10 and score< 20 then '10-19'
- else '20-99' end as range
- from scores) t
- group by t.range
- select t.range as [score range], count(*) as [number of occurences]
- from (
- select case
- when score between 0 and 9 then ' 0-9 '
- when score between 10 and 19 then '10-19'
- when score between 20 and 29 then '20-29'
- ...
- else '90-99' end as range
- from scores) t
- group by t.range
- create table scores (
- user_id int,
- score int
- )
- select t.range as [score range], count(*) as [number of occurences]
- from (
- select user_id,
- case when score >= 0 and score < 10 then '0-9'
- case when score >= 10 and score < 20 then '10-19'
- ...
- else '90-99' as range
- from scores) t
- group by t.range
- select (score/10)*10 || '-' || (score/10)*10+9 as scorerange, count(*)
- from scores
- group by score/10
- order by 1
- scorerange | count
- ------------+-------
- 0-9 | 11
- 10-19 | 14
- 20-29 | 3
- 30-39 | 2
- LowerLimit UpperLimit Range
- 0 9 '0-9'
- 10 19 '10-19'
- 20 29 '20-29'
- 30 39 '30-39'
- Select
- Range as [Score Range],
- Count(*) as [Number of Occurences]
- from
- Ranges r inner join Scores s on s.Score between r.LowerLimit and r.UpperLimit
- group by Range
- SELECT
- [score range] = CAST((Score/10)*10 AS VARCHAR) + ' - ' + CAST((Score/10)*10+9 AS VARCHAR),
- [number of occurrences] = COUNT(*)
- FROM #Scores
- GROUP BY Score/10
- ORDER BY Score/10
- select cast(score/10 as varchar) + '-' + cast(score/10+9 as varchar),
- count(*)
- from scores
- group by score/10
- declare @RangeWidth int
- set @RangeWidth = 10
- select
- Floor(Score/@RangeWidth) as LowerBound,
- Floor(Score/@RangeWidth)+@RangeWidth as UpperBound,
- Count(*)
- From
- ScoreTable
- group by
- Floor(Score/@RangeWidth)
Add Comment
Please, Sign In to add comment