此代码有效:

select Date1,  Date2
from
    (SELECT Date1 FROM Table1 GROUP BY Date1) t1
left join
    (SELECT Date2 FROM Table2 GROUP BY Date2) t2
on
    t1.Date1 = t2.Date2


但是我需要使用它来提取Month(...),所以当我更改这样的代码时,我得到了一个错误:


  “字段列表”中的未知列“ Date1”


select Date1,  Date2
from
    (SELECT Month(Date1) FROM Table1 GROUP BY Date1) t1
left join
    (SELECT Month(Date2) FROM Table2 GROUP BY Date2) t2
on
    t1.Date1 = t2.Date2


实际上,代码更大,并且只有这部分代码不允许我继续进行。

最佳答案

内部选择查询中缺少month的别名

select Date1,  Date2
from
    (SELECT Month(Date1) as date1 --Alias missing Here
     FROM Table1
     GROUP BY Date1) t1
left join
    (SELECT Month(Date2) as date2 --Alias missing here
     FROM Table2
     GROUP BY Date2) t2
on
    t1.Date1 = t2.Date2

关于mysql - sql在选择语句中使用Month(date)的左连接错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31773852/

10-11 03:37