gpt4 book ai didi

mysql - 在选择语句中使用月份(日期)时出现sql左连接错误

转载 作者:行者123 更新时间:2023-11-29 12:04:30 24 4
gpt4 key购买 nike

此代码正在运行:

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(...),所以当我更改这样的代码时,我收到错误:

Unknown column 'Date1' in 'field list'

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

实际上代码更大,只有这部分代码不允许我继续..

最佳答案

内部选择查询中缺少月份别名

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左连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31773852/

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