JFreeChart使用数字查询ORACLE

时间:2013-04-17 02:13:27

标签: oracle jfreechart bar-chart

晚安!

我有一个名为SWIMMER的表,需要找到(在名为TIME的NUMERIC字段中)给定时间间隔内某些值的ocorrence数(我使用的是Oracle10g)。 我需要展示类似的东西:

23更高或相等TIME显示Horizo​​ntalBar值为300
22,3更高或相等TIME次要或相等23显示Horizo​​ntalBar值140
21,6更高或相等TIME次要或等于22,3显示Horizo​​ntalBar值为15
20,9更高或相等TIME次要或相等21,6显示Horizo​​ntalBar值3

可能有一个查询有这样的返回?我怎么能组装该查询? (注意:次要或相等是符号,我不能在这里发帖,因为它每次都会出错)

最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

尝试这样的事情(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 

和结果:

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

更新:正如DavidAldrige建议你可以有一个子查询:

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