我附上了示例資料。這里實際上我想一起計算 emp_contribution 和 vpf 列的運行總數。但是,這應該限制在一個財政年度內。假設2015年從2015年4月開始到2016年3月。這就是我面臨的挑戰。
下面我附上了我的嘗試查詢,但在 where 子句過濾器下無法正常作業
select
case when sum(isnull(emp_contribution,0)) over(partition by emp_no order by pcm_month) sum(isnull(vpf,0)) over(partition by emp_no order by pcm_month) < 3000
then sum(isnull(emp_contribution,0)) over(partition by emp_no order by pcm_month) sum(isnull(vpf,0)) over(partition by emp_no order by pcm_month)
else null
end empcontbtnwithouttax,
case
when sum(isnull(emp_contribution,0)) over(partition by emp_no order by pcm_month) sum(isnull(vpf,0)) over(partition by emp_no order by pcm_month) >= 3000
then sum(isnull(emp_contribution,0)) over(partition by emp_no order by pcm_month) sum(isnull(vpf,0)) over(partition by emp_no order by pcm_month)
else null
end empcontbtnwithtax,
pcm_month, pcm_year, emp_no
from
[dbo].[pf_contribution_master]
where
(pcm_year >= 2015 and pcm_month >= 4 )
and (pcm_year <= 2016 and pcm_month < 4 )
and emp_no= 11101201
order by
pcm_year, pcm_month

uj5u.com熱心網友回復:
WHERE子句中的額外計算可能會有所幫助:
...
WHERE
(pcm_year * 100 pcm_month >= 201504) AND
(pcm_year * 100 pcm_month < 201604) AND
(emp_no = 11101201)
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/389540.html
標籤:sql sql-server 查询语句
上一篇:存盤程序中的SETQUOTED_IDENTIFIERON不起作用
下一篇:替換函式SQL
