我有一個column
在SQL table
。包含交貨訂單的date
。如何計算每學期的營業額
所以同一日期可以重複(在有一天我們delivred severals訂單),像這樣:
05-01-16
05-01-16
05-01-16
08-01-16
08-01-16
14-01-16
22-01-16
22-01-16
04-02-16
05-02-16
05-02-16
我想,計算在each 6 months
每篇文章的營業額的AVG,我更多地解釋:
From January to June ==> Turnover 1
From Febrary to July ==> Turnover 2
From March to August ==> Turnover 3
From April to September ==> Turnover 4
From May to Obtober ==> Turnover 5
From June to November ==> Turnover 6
From July to December ==> Turnover 7
我已經提取的月份由請求波紋管,但我不能動態地計算(因爲我的數據應該是每個月變化)成交像上面這個例子:
select distinct extract (month from Article) as mt
order by mt
我試圖使用cursor
,但我無法抵達最佳解決方案。
我做的請求來計算每文章每個客戶的營業額在the first 6 months
(I手動做到了)如下:
select "LRU", "Client", round(sum("Montant_fac_eur"))
from "foundry"
where "Nature"='Repair'
and "Client"={{w_widget3.selectedValue}}
and "annee"='2016'
and extract (month from "date") between '1' and '6'
group by "LRU", "Client"
她的結果如下:
LRU Client round
"article1" 4001 8859 Turnover of article1 from January to June
"article2" 4001 94315 Turnover of article2 from January to June
"article3" 4001 273487 Turnover of article3 from January to June
"article4" 4001 22292 Turnover of article4 from January to June
"article5" 4001 22292 Turnover of article5 from January to June
"article6" 4001 42590 Turnover of article6 from January to June
"article7" 4001 9965 Turnover of article7 from January to June
"article8" 4001 39654 Turnover of article8 from January to June
"article9" 4001 3883 Turnover of article9 from January to June
"article10" 4001 41612 Turnover of article10 from January to June
我想要做一個循環來計算每6個月的營業額,如果可能的話無需手動編寫它? 有人可以幫助我,給我一個解決方案或建議我該怎麼做? 謝謝。
你能不能請張貼樣本輸入和預期的輸出? –
我改變了我上面的問題。謝謝。 – vero
在沒有敏感數據的情況下獲取「代工」表的模式將非常有用。例如。更改列名稱。 –