我有一个疑问
SELECT sum(cash) from bought_cash WHERE uid=1 AND source NOT IN ('a', 'b')
给出的结果为140
和
SELECT sum(cash) from bought_cash WHERE uid=1 AND source IN ('a', 'b')
给出NULL
和
SELECT sum(cash) from bought_cash WHERE uid=1
给出的结果为240
和
SELECT sum(cash) from bought_cash WHERE uid=1 and source is null
给出的结果为100
如何编写查询,以便第一个查询通过包含空值给出 240
结果。
最佳答案
接下来您也可以尝试:
select sum(cash)
from bought_cash
where uid = 1 and (source is null or source not in ('a', 'b'))
关于mysql - 如何通过包含空值来编写查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14693637/