gpt4 book ai didi

mysql - 当在查询中使用 sum() 时没有结果返回 null

转载 作者:行者123 更新时间:2023-11-29 09:39:45 24 4
gpt4 key购买 nike

在查询中使用 sum() 且结果不返回空行时

例如我有这张表:

 | id | name | visit | active |

| 1 | ali |  4   |    0   |

| 2 | ali |  8   |    0   |

我运行这个查询:

select name, sum(visit) visit

from table

where active = 1

因为这个查询不是结果

返回此:

| name | visit |

| null | null |

我不想在结果中出现任何行

我可以用sql方式解决这个问题吗?

最佳答案

select name, sum(visit)
from table
where active = 1
group by name
having sum(visit) is not null;

关于mysql - 当在查询中使用 sum() 时没有结果返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56868279/

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