SELECT SUM 在没有记录时返回一行 [英] SELECT SUM returns a row when there are no records

查看:50
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆