2013-04-17 20 views
0

晚上好!使用數字查詢的JFreeChart ORACLE

我有一個名爲SWIMMER的表,需要在給定的時間間隔(我使用Oracle10g)中找到(在名爲TIME的NUMERIC字段中)某些值的出現次數。 我需要顯示類似的東西:

23大於或等於時間表示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

嘗試是這樣的(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

+0

+1:我想我可能會推案到對結果的子查詢和彙總,以避免重複的是複雜的表達式雖然。 –

+0

A.B.Cade,感謝您的輸入!我會研究你的代碼,並在晚些時候獻上! – PaulHB

+0

大衛奧爾德里奇,我怎麼可以在這個例子中使用子查詢?我只寫了我的問題的最小部分來簡化答案,但有時,我會有超過四個表達式顯示在條形圖(有時10)。謝謝! – PaulHB