Вопрос

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