簡體   English   中英

Oracle頂點圖表-折線圖SQL?

[英]oracle apex chart - line graph sql?

select count(case when extract(month from C_DATE) = 1 then 1 end) as Jan,
   count(case when extract(month from C_DATE) = 2 then 1 end) as feb,
   count(case when extract(month from C_DATE) = 3 then 1 end) as mar,
   count(case when extract(month from C_DATE) = 4 then 1 end) as april,
   count(case when extract(month from C_DATE) = 5 then 1 end) as may,
   count(case when extract(month from C_DATE) = 6 then 1 end) as jun,
   count(case when extract(month from C_DATE) = 7 then 1 end) as jul,
   count(case when extract(month from C_DATE) = 8 then 1 end) as aug,
   count(case when extract(month from C_DATE) = 9 then 1 end) as sep,
   count(case when extract(month from C_DATE) = 10 then 1 end) as oct,
   count(case when extract(month from C_DATE) = 11 then 1 end) as nov,
   count(case when extract(month from C_DATE) = 12 then 1 end) as december
from Table1

目前,這是我產生結果的查詢

Jan Feb Mar Apr .....
1   3    1   2

現在我想在折線圖中顯示此信息,所以看起來像這樣

3       x
2
1  x           x
  jan   feb   mar 

作為圖表的菜鳥,當我嘗試使用當前查詢時,我無法使其正常工作。 任何幫助非常感謝

如果您真的想使用ASCII圖形,並且代替更詳細的說明,則可以繼續

WITH
Line AS (
  SELECT
    ' ' || Jan || '  ' || Feb || '  ' || Mar || '  ' || Apr || '  ' || May || '  ' || Jun || '  ' || Jul || '  ' || Aug || '  ' || Sep || '  ' || Oct || '  ' || Nov || '  ' || Dec || ' ' l
  FROM Result
),
Graph (cnt, g)AS (
  SELECT 5, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 5 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT 4, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 4 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT 3, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 3 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT 2, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 2 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT 1, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 1 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT 0, '#' || REGEXP_REPLACE(REGEXP_REPLACE(l, ' 0 ', '  x  '), '\d+', '   ') || '#' FROM Line UNION ALL
  SELECT -1, '# Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec #' FROM DUAL
)
SELECT
  *
FROM Graph
ORDER BY cnt DESC
;

其中“結果”是您對Table1的查詢。

請參見SQL Fiddle (切換到純文本輸出以查看正確對齊的列。)
您是否嘗試過使用Oracle Application Express 4.0構建圖表,甘特圖和地圖 如果需要調整,請發表評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM