Mysql 内部联接3表pl/sql
基本上,我希望内部连接3个表,查询本身对这种情况的理解如下 表:Mysql 内部联接3表pl/sql,mysql,sql,Mysql,Sql,基本上,我希望内部连接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.colum
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不存在
为什么会这样?查询有错误吗?问题在于,您使用的别名是
C
,而您不应该在该别名中使用count
功能。这:
C.Count(C.column6)
应该是:
Count(C.column6)
同样的更改也适用于order by子句(这可能是计算错误的列-是否应该是第6列?):
按计数排序(第5列)说明
->按计数排序(第6列)说明
另外:您应该引用GROUPBY
子句中的所有非聚合列,因此它可能应该是GROUPBY A.column1