我想计算查询结果的值,但如果有意义,则在同一查询中。原始查询是
SELECT CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER as BAL, total_closing_balance
FROM statement
这会返回超过4000行。我想检查两个加起来。有没有办法在同一个查询中使用count函数来计算select语句的前两个值?
或者我是否必须使用像临时表这样的东西然后计算?
答案 0 :(得分:0)
使用Select sum(CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER )
它将添加所有这些细节。
答案 1 :(得分:0)
如果total_closing_balance是静态的话,请尝试这个
SELECT SUM(CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER) as BAL, MAX(total_closing_balance) AS total_closing_balance FROM isql.VW_300_statement WHERE brand = '1'AND DAT = '2013-01-18 00:00:00.00000'AND INS_TYPE =''group by Brand,DAT
答案 2 :(得分:0)
为了计算查询结果的行数,您必须按如下方式编写查询:
select count(*)
from (SELECT CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER as BAL, total_closing_balance
FROM isql.VW_300_statement
WHERE brand = '1'
AND DAT = '2013-01-18 00:00:00.00000'
AND INS_TYPE ='')