2017-06-13 107 views
-2

我是新手,我很困惑如何做求和查詢。這裏是我的查詢:在sql server上SUM查詢

enter image description here

,這是從我的查詢輸出:

enter image description here

我想要的總和一個月我presentase場..

我已經創建的總和查詢,但所有我會得到我的查詢只是錯誤代碼:(((..)

這裏我的總結查詢Y:

SUM(IF(YEAR(PO_HARI) = 2016, PRESENTASE_SATUAN, 0)) AS TOTAL_JANUARY 

,也是我加入TOTAL_JANUARY在我group_by但沒有工作。

感謝您的關注。

+0

應該是IIF和group by應該是參考字段 – maSTAShuFu

+0

我不知道如何實施你的建議sir Mastafshu ..你能舉一些例子嗎? – adityajhordan

+1

你必須做一些挖掘......這並不難 – maSTAShuFu

回答

0

如果你使用的SQL Server Management Studio中那麼試試這個:::

select sum(presentase) from tablename 
group by month(PO_HARI) 
--here i am assuming that "presentase" is a summable field and 'po_hari' is a date column 
0

試試這個

select year(po_date) yeardate, month(po_date) monthdate, 
     sum(case Point_del 
      when 1 then 25 
      when 2 then 50 
      when 3 then 75 
      when 4 then 100 
      else 0 
      ) TOTAL_JANUARY 
from jbox2_po..POT01A 
where month(po_date)=1 
group by year(po_date) , month(po_date) 

你可以添加 '和年份(po_date)= 2016' 到where子句中,如果你只想要2016年