基本上我想内连接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不存在
为什么会这样?查询有什么错误吗?
答案 0 :(得分:2)
问题是您使用C
功能的别名count
。这样:
C.Count(C.column6)
应该是:
Count(C.column6)
并且同样的更改适用于order by
子句(可能计算错误的列 - 如果它不是column6?):
order by C.count(column5) desc
- > order by count(column6) desc
另外:您应该引用group by
子句中的所有非聚合列,因此它应该是group by A.column1