2
代碼的第一部分基於SUM語句創建一個表:結合和語句一個表
SELECT varday, COUNT(*) AS Vol,
SUM(FOPS_REHAB) AS FOPS_REHAB,
SUM(FOPS_RECOVERY) AS FOPS_RECOVERY
FROM table
WHERE PROCESSING_DATE > '31/aug/2012' and rownumber =1
GROUP BY varday
ORDER BY varday
但是,我有我想以上組合成的編碼其他兩個代碼部分,但他們有一個額外的'where'標準。
因此,這些是我想要結合上面表格的兩個總和表述;
select SUM(Current_Balance_Amount)as rec_bal, varday
into #temp
from table
where fops_recovery = 1 and PROCESSING_DATE > '31/aug/2012' and rownumber =1
group by varday
ORDER BY varday
select SUM(Current_Balance_Amount)as reh_bal, varday
into #temp
from table
where fops_rehab = 1 and PROCESSING_DATE > '31/aug/2012' and rownumber =1
group by varday
ORDER BY varday
所以reh_bal
和rec_bal
是在一個表包含FOPS_REHAB
和FOPS_RECOVERY
第一個表。我有問題,因爲他們有一個額外的條款(where fops recovery = 1 or fops rehab = 1
)。