gpt4 book ai didi

mysql - ISNULL(col,0) 和 "notexists(col,0)"

转载 作者:行者123 更新时间:2023-11-30 01:18:02 24 4
gpt4 key购买 nike

在此查询中(一个简单的示例,我的实际查询更复杂)

SELECT SUM(ISNULL(Quantity, 0)) from Product_SalRec where Date between '1-20-2013' and '1-25-2013'

或者只是

SELECT isnull(id,0) from table_1 where id = 123456789

它返回一个“空白”列,因为该范围内不存在行...即使使用 Isnull() 时,我已经尝试过 --CASE when '' then 0--,但对我不起作用。有没有一个函数可以显示0而不是空白?

最佳答案

尝试

SELECT SUM(IFNULL(Quantity, 0)) from Product_SalRec where Date between '1-20-2013' and '1-25-2013'.

根据the mysql reference isnull() 检查参数是否为空。

关于mysql - ISNULL(col,0) 和 "notexists(col,0)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18856522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com