代码的第一部分基于 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
但是,我还有两个其他代码部分要合并到上面的代码中,但它们有一个额外的“位置”标准。
所以这些是我想结合到上表中的两个 sum 语句;
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
)。