JFreeChart using numeric query ORACLE

有些话、适合烂在心里 提交于 2019-12-12 00:48:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!