我有一个sql语句的问题。 我的数据库是MySQL 5.1。连接的SQL返回默认值不存在属性
我有2个表:
day_table
date(pk) note ...
------- ----- ---
2012-03-29 foo ...
2012-03-30 bar ...
2012-03-31 foobar ...
other_table
id fk_date key value
-- ------- --- -----
1 2012-03-29 foo 5
2 2012-03-30 bar 9
3 2012-03-30 foo 4
4 2012-03-31 bar 6
5 2012-03-31 foo 1
所以我需要一个查询是这样的:
SELECT o.value, d.date FROM other_table o join day_table d on (...) where key = "bar" group by d.date;
我需要这样一个结果:
result_table
date(pk) value
------- -----
2012-03-29 0 (or null) <---- THIS IS IMPORTANT!!!
2012-03-30 9
2012-03-31 6
我知道问题在于加入,但我需要在day_table中获取每个日期。
(My)SQL可能吗?
问候
我试过这个,但结果是没有“2012-03-29 0” – veote 2012-04-02 08:31:17
现在试试它应该工作.. – Vikram 2012-04-02 09:19:49
疯狂它确实与这些表一起工作。但不是用我的“真实”桌子...... – veote 2012-04-02 11:08:42