From Table
A   B
_______________
1   A
3   B
6   C
7   C
8   X   
9   Y
15  Z
16  R
17  t   
23  T
43  e
How to bring this result:
Range A  Count B
_________________
1-10    6
11-20   3
21-30   1
31-40   1
This could be done using loop:
Select Count (* ) from TableA where b between @a and @b
But I would like to do it without using any loop is it possible?
Try this:
SELECT 
Cast(((A / 10) * 10 + 1) as varchar(100)) + '-' + Cast(((A / 10) * 10 + 10) as varchar(100)) AS 'Range A',
Count(*) as 'Count B'
 FROM TableA
GROUP BY A / 10
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With