繁体   English   中英

内部联接3个表pl / sql

[英]Inner Join 3 tables pl/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.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子句中应用了相同的更改(该计数可能计算出错误的列-不应为column6吗?):

order by C.count(column5) desc order by count(column6) desc -> order by count(column6) desc

另外:您应该在group by子句中引用所有未聚合的列,因此它可能应该group by A.column1进行group by A.column1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM