没有记录时,SELECT SUM返回一行 [英] SELECT SUM returns a row when there are no records
本文介绍了没有记录时,SELECT SUM返回一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在查询中发现了一些问题,该查询从表中返回满足特定条件的所有记录的字段总和.我希望在没有记录时会收到找不到记录",但是我收到的是空结果.
I'm finding some problems with a query that returns the sum of a field from a table for all the records that meet certain conditions. I expected to receive a "No records found' when there were no records, but instead I'm receiving a null result.
SQL> SELECT * FROM DUAL WHERE 1=2;
no rows selected
SQL> SELECT SUM(dummy) FROM DUAL WHERE 1=2;
SUM(DUMMY)
----------
SQL>
在这种情况下,有什么方法可以不接收任何记录吗?
Is there any way to not receive any record in that case?
推荐答案
这是怎么回事:
select my_sum
from
(SELECT SUM(dummy) as my_sum FROM DUAL WHERE 1=2)
where
my_sum is not null
这篇关于没有记录时,SELECT SUM返回一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文