问题
Good Evening!
I have a Table named SWIMMER, and need to find(in the NUMERIC field named TIME)the number of ocorrence of some values in a given interval(I am using Oracle10g). I need to show something like that:
23 higher or equal TIME Shows HorizontalBar with value 300
22,3 higher or equal TIME minor or equal 23 Shows HorizontalBar with value 140
21,6 higher or equal TIME minor or equal 22,3 Shows HorizontalBar with value 15
20,9 higher or equal TIME minor or equal 21,6 Shows HorizontalBar with value 3
Its possible to have a query to have a return like that?How could i assembly that query? (Note: minor or equal are the Symbols,i can not post here because it is giving errors everytime)
Best Regards,
回答1:
Try something like this (Here is a sqlfiddle):
select case
when time >= 23 then '23 =< TIME'
when time < 23 and time >= 22.3 then '23 > TIME >= 22,3'
when time < 22.3 and time >= 21.6 then '22,3 > TIME >= 21,6'
when time < 21.6 and time >= 20.9 then '21,6 > TIME >= 20,9'
else '20,9 > TIME'
end || ' with value '|| count(*) v
from your_table
group by case
when time >= 23 then '23 =< TIME'
when time < 23 and time >= 22.3 then '23 > TIME >= 22,3'
when time < 22.3 and time >= 21.6 then '22,3 > TIME >= 21,6'
when time < 21.6 and time >= 20.9 then '21,6 > TIME >= 20,9'
else '20,9 > TIME'
end
and the results:
21,6 > TIME >= 20,9 with value 8
20,9 > TIME with value 4
22,3 > TIME >= 21,6 with value 6
23 > TIME >= 22,3 with value 15
23 =< TIME with value 66
UPDATE: As DavidAldrige suggested you can have a subquery:
select intrvl || ' with value '|| count(*) v
from
(select case
when time >= 23 then '23 =< TIME'
when time < 23 and time >= 22.3 then '23 > TIME >= 22,3'
when time < 22.3 and time >= 21.6 then '22,3 > TIME >= 21,6'
when time < 21.6 and time >= 20.9 then '21,6 > TIME >= 20,9'
else '20,9 > TIME'
end intrvl, time
from t)
group by intrvl
And here is another demo
来源:https://stackoverflow.com/questions/16050280/jfreechart-using-numeric-query-oracle