mysql - 内连接 3 个表 pl/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.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/

相关文章:

python - 当我尝试使用 python 迭代 mysql 的结果时出现重复项

mysql - 如何找到mysql varchar列的最大值

mysql - 如何建立数据库与数据库之间的关系?

MYSQL 组合使用相同列的两个计数

sql - 在 SQL Server 中解析 JSON

sql - 是否可以在不安装数据库服务器的情况下打开 Firebird 数据库文件?

python - 我应该在数据库中进行数值计算吗?

php - 将 mysql 结果存储在 SESSION 数组中以供以后使用(通过 in_array 检查)

c# - 使用 Entity SQL 查询概念模型

php - 从 mysql 数据填充的动态下拉列表