October 3, 2008 at 5:11 am
Hello,
I need to group and count data values from a table to get a result like:
Limits Total
[0-5] 2
[6-10] 3
[10-100] 1
how can I do this?
Thank you,
Augusto
October 3, 2008 at 5:14 am
Hi Augusto
This is usually straightforward - what does your source table look like? Can you post DDL with some sample data please?
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
October 3, 2008 at 5:17 am
Try
selectcase
when col between 0 and 5 then '[0-5]'
when col between 6 and 10 then '[6-10]'
when col between 11 and 100 then '[11-100]'
end as Limits,
count(*) as Total
from
your_table
group by
case
when col between 0 and 5 then '[0-5]'
when col between 6 and 10 then '[6-10]'
when col between 11 and 100 then '[11-100]'
end
Failing to plan is Planning to fail
October 3, 2008 at 5:40 am
Hello,
Madhivanan, your example help me to solve my problem.
Thank you,
Augusto
October 3, 2008 at 7:13 am
amfps (10/3/2008)
Hello,Madhivanan, your example help me to solve my problem.
Thank you,
Augusto
You are welcome ๐
Failing to plan is Planning to fail
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply