基本上我想内连接 3 个表,查询本身可以理解这种情况,如下所示。
表格:
A has 2 columns column 1 and column 2
B has 2 columns column 3 and column 4
C has 3 columns column 5,column 6 and column 7
查询:
select A.column1, C.Count(C.column6)
from table1 as A inner join table3 as C on A.column2 = C.column5
inner join table2 as B on C.column5 = B.column4 and column3 = 'abcd'
where column7 > NOW() - Interval '30 days'
group by C.column5
order by C.count(column5) desc
但我收到错误模式 C 不存在
为什么会发生这种情况?查询有错误吗?
最佳答案
问题在于您在 count
函数中使用了不应使用的别名 C
。这:
C.Count(C.column6)
应该是:
Count(C.column6)
同样的更改也适用于 order by
子句(这可能会计算错误的列 - 不应该是第 6 列吗?):
按 C.count(column5) desc 排序
-> 按 count(column6) desc 排序
另外:您应该在 group by
子句中引用所有非聚合列,因此它可能应该是 group by A.column1
关于mysql - 内连接 3 个表 pl/sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30983771/