Not sure how to word the question:

I have a query such as

SELECT s.*
FROM SUMMARY s
WHERE s.TYP = 'A'
AND s.NUM > 0
AND s.NUM <= 999999

and a group by like

SELECT s.TYP, s.COUNT(TYPE)
FROM SUMMARY s
GROUP BY s.TPY

which gives:

A 38720
B 39500
C 170
D 850
E 8891

What I'd like to do is get a "split" of my results using a "range" like:

TYP RANGE(NUM) COUNT
  A 0000>1000  240
  A 1000>2000  800
  A 2000>3000  120
etc...

Is there a simple way of doing this?

有帮助吗?

解决方案

Look at IF in the SELECT command to group by ranges you have in the rows and then PIVOT fction to flip the result.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top