gpt4 book ai didi

php - Mysql如果不存在则返回0

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

我有一个像这样的 mysql 表:

date           data
01-01-2005 10 |
02-01-2005 11|
03-01-2005 13|
07-01-2005 20|

我怎样才能像下面这样列出

date           data:
01-01-2005 10|
02-01-2005 11|
03-01-2005 13|
04-01-2005 0|
05-01-2005 0|
06-01-2005 0|
07-01-2005 20|

编辑:我使用这样的日历表:

date:
01-01-2005 for all 365 days.

这是我最好的意见,但它不起作用:

SELECT c.steps, IFNULL(c.steps, 0) value, r.calendar_date
FROM log_activities c
LEFT JOIN calendar r
ON (r.calendar_date = c.date_logged)
WHERE email = 'a@mail.com'
ORDER BY c.date_logged DESC

最佳答案

尝试:

SELECT c.steps, IFNULL(c.steps, 0) value, r.calendar_date
FROM log_activities c
right JOIN calendar r
ON r.calendar_date = c.date_logged
WHERE email = 'a@mail.com'
and substr(r.calendar_date, 4, 2) = '01'
and r.calendar_date between
(select min(date_logged) from log_activities) and
(select max(date_logged) from log_activities)
ORDER BY c.date_logged DESC

关于php - Mysql如果不存在则返回0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336176/

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