您必须从某处获取各个日期值。如果您不想创建临时表,可以将值直接嵌入到语句中的子查询中:
SELECT IFNULL(Slider_Value, 'none')
FROM (SELECT '2013-10-01' AS Date
UNION ALL
SELECT '2013-10-02'
UNION ALL
SELECT '2013-10-03'
UNION ALL
...
SELECT '2013-10-31'
) AS ThisMonth
LEFT JOIN Tbl_Activity_Tracks ON ThisMonth.Date = date(Track_Date_Time)
如果您不想枚举生成 SQL 语句的代码中的日期,您也可以在 SQL 本身中执行此操作,但需要足够的扭曲:
SELECT IFNULL(Slider_Value, 'none')
FROM (SELECT date('now', 'start of month') AS Date
UNION ALL
SELECT date('now', 'start of month', '+1 days')
UNION ALL
SELECT date('now', 'start of month', '+2 days')
UNION ALL
...
UNION ALL
SELECT date('now', 'start of month', '+27 days')
UNION ALL
SELECT date('now', 'start of month', '+28 days') WHERE strftime('%m', 'now', 'start of month', '+28 days') = strftime('%m', 'now')
UNION ALL
SELECT date('now', 'start of month', '+29 days') WHERE strftime('%m', 'now', 'start of month', '+29 days') = strftime('%m', 'now')
UNION ALL
SELECT date('now', 'start of month', '+30 days') WHERE strftime('%m', 'now', 'start of month', '+30 days') = strftime('%m', 'now')
) AS ThisMonth
LEFT JOIN Tbl_Activity_Tracks ON ThisMonth.Date = date(Track_Date_Time)
(对于少于 31 天的月份,最后三个 WHERE 子句省略了当前月份中不再存在的日期。)