January 13, 2017 at 1:07 am
Hi,
Below is my query,
select t.range as [score range], count(*) as [number of occurences]
from (
select case
when answer_count between 0 and 5 then ' 0- 9'
when answer_count between 5 and 10 then '10-19'
else '20-99' end as range
from points where type='product_quiz') t
group by t.range
The output is,
score range number of occurences
10-19 121327
0- 9 129195
But I want the output as,
score_range number_of_occurences score_range1 number_of_occurences1
10-19 121327 10-19 121327
0- 9 129195 0- 9 129195
Please help me to achieve this.
Thanks in Advance,
Best Regards,
Poornima
January 13, 2017 at 1:46 am
poornima.s_pdi - Friday, January 13, 2017 1:07 AMHi,Below is my query,
select t.range as [score range], count(*) as [number of occurences]
from (
select case
when answer_count between 0 and 5 then ' 0- 9'
when answer_count between 5 and 10 then '10-19'
else '20-99' end as range
from points where type='product_quiz') t
group by t.rangeThe output is,
score range number of occurences
10-19 121327
0- 9 129195But I want the output as,
score_range number_of_occurences score_range1 number_of_occurences1
10-19 121327 10-19 121327
0- 9 129195 0- 9 129195
Please help me to achieve this.Thanks in Advance,
Best Regards,
Poornima
SELECT
t.[range] as [score range], COUNT(*) as [number of occurences],
t.[range] as [score range1], COUNT(*) as [number of occurences1]
FROM (
SELECT CASE
WHEN answer_count BETWEEN 0 AND 5 THEN ' 0- 9'
WHEN answer_count BETWEEN 5 AND 10 THEN '10-19'
ELSE '20-99' END as [range]
FROM points
WHERE [TYPE_ID] = 'product_quiz'
) t
GROUP BY t.[range]
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 13, 2017 at 2:02 am
Hi,
I need to achieve the above result using sub-query for the duplicating columns.
January 13, 2017 at 2:08 am
poornima.s_pdi - Friday, January 13, 2017 2:02 AMHi,
I need to achieve the above result using sub-query for the duplicating columns.
Yes you can do it that way too, although in my opinion it renders the query a little wordy.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
January 13, 2017 at 3:31 am
ChrisM@Work - Friday, January 13, 2017 2:08 AMpoornima.s_pdi - Friday, January 13, 2017 2:02 AMHi,
I need to achieve the above result using sub-query for the duplicating columns.Yes you can do it that way too, although in my opinion it renders the query a little wordy.
This is starting to sound like homework ....
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply