gpt4 book ai didi

mysql如果没有记录

转载 作者:行者123 更新时间:2023-11-29 14:01:14 25 4
gpt4 key购买 nike

我有一个这样的查询;

select value, date from table
where date in ('date1','date2','date3','date4','date5')
group by date

仅当存在给定日期的记录时才会给出结果。但我想获得一行值为“0”的行,即使没有给定日期之一的记录。我该怎么做?

5 | 02/04/2012
8 | 02/05/2012
3 | 02/06/2012
4 | 02/08/2012

>

5 | 02/04/2012
8 | 02/05/2012
3 | 02/06/2012
0 | 02/07/2012
4 | 02/08/2012

最佳答案

您需要使用日期表,或创建一个包含日期的临时表。但是,日期表将是您的最佳选择,因为它尺寸小且效率高。

您还错误地使用了GROUP BY。请阅读MySQL Extensions to GROUP BY .

关于mysql如果没有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026962/

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