0

我想计算查询结果中的值,但如果有意义的话,在同一个查询中。原始查询是

SELECT CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER as BAL, total_closing_balance
FROM statement

这将返回超过 4000 行。我想检查这两个加起来。有没有办法在同一个查询中使用 count 函数来计算 select 语句的前两个值?

还是我必须使用临时表之类的东西然后计数?

4

3 回答 3

0

利用Select sum(CLOSING_FEE+CLOSING_FEE_INT+CLOSING_INS+CLOSING_INT+CLOSING_OTHER )

它将添加所有这些细节。

于 2013-10-03T11:48:07.790 回答
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 ='')
于 2013-10-03T11:56:13.320 回答
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
于 2013-10-03T11:51:03.297 回答