我想要连接2个表。 因此,左表的所有属性都应显示在结果表中,而不管它是否可以与其他表连接。MySQL左连接无法正常工作
当我做follwing,我没有得到预期的结果
week_table:
date kw note
---------- -- ----
2012-04-01 0 NULL
2012-04-02 0 NULL
fact_table:
id number_of_application number_of_cluster number_of_jvm number_of_node number_of_was fk_wasversion fk_date fk_domain fk_osname fk_osarch fk_osversion fk_stage
-- --------------------- ----------------- ------------- -------------- ------------- ------------- ---------- --------- --------- --------- ------------ --------
1 114 8 80 18 18 6.0 2012-04-01 domain1 Linux sparc 2 stage1
2 114 8 80 18 18 6.0 2012-04-02 domain1 Linux sparc 2 stage1
3 114 8 80 18 18 6.0 2012-04-01 domain1 AIX sparc 2 stage1
4 114 8 80 18 18 6.0 2012-04-02 domain1 Solaris sparc 2 stage1
当我这样做:
select
w.date,
coalesce(sum(f.number_of_was), 0)
from
week_table w
left join fact_table f on (w.date = f.fk_date)
where f.fk_osname = "AIX"
group by w.date;
我只得到:
date coalesce(sum(f.number_of_was), 0)
---------- ---------------------------------
2012-04-01 18
预计:
date coalesce(sum(f.number_of_was), 0)
---------- --------------------------------
2012-04-02 18
有人知道为什么吗?
问候
大非常感谢你只检索行 - 这工作 – veote 2012-04-02 13:13:50