0

运行此脚本时出现上述错误:

SELECT s1.Station_Name as Station, s1.St_Town as Town, cg1.CaporGen as Type, ht1.HYDRO_NAME as Typology
FROM station s1, capacityandgeneration cg1, hydro_type ht1
JOIN station s2 ON cg1.station_id=s2.Station_ID
inner join hydro_type ht2 on cg2.hydro_type_id=ht2.type_id;

但是当我删除第三张桌子时它工作正常:

SELECT s1.Station_Name as Station, s1.St_Town as Town, cg1.CaporGen as Type
FROM station s1, capacityandgeneration cg1
JOIN station s2 ON cg1.station_id=s2.Station_ID;

我已经尝试了使用列别名的各种排列,但不断出现上述错误。请告诉我我的方式的错误,因为我现在很困惑。

干杯西蒙

4

2 回答 2

0
SELECT s1.Station_Name as Station, s1.St_Town as Town, cg1.CaporGen as Type, ht1.HYDRO_NAME as Typology
FROM station s1
join capacityandgeneration cg1
join hydro_type ht1
JOIN station s2 ON cg1.station_id=s2.Station_ID
inner join hydro_type ht2 on cg2.hydro_type_id=ht2.type_id; 

尝试这个。如果列存在,那么应该没有任何问题

于 2013-07-22T10:45:36.543 回答
0

JOIN语法中所述:

 在 MySQL 5.0.12 中加入处理更改

[删除]

以下列表提供了有关当前连接处理与旧版本中连接处理的几种效果的更多详细信息。“以前”一词的意思是“在 MySQL 5.0.12 之前”。</p>

[删除]
  • 以前,逗号运算符 ( ,) 和JOIN两者具有相同的优先级,因此连接表达式t1, t2 JOIN t3被解释为((t1, t2) JOIN t3)。NowJOIN具有更高的优先级,因此表达式被解释为(t1, (t2 JOIN t3)). 此更改会影响使用ON子句的语句,因为该子句只能引用连接操作数中的列,并且优先级的更改会更改对这些操作数的解释。

    例子:

    CREATE TABLE t1 (i1 INT, j1 INT);
    CREATE TABLE t2 (i2 INT, j2 INT);
    CREATE TABLE t3 (i3 INT, j3 INT);
    INSERT INTO t1 VALUES(1,1);
    INSERT INTO t2 VALUES(1,1);
    INSERT INTO t3 VALUES(1,1);
    SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);
    

    以前,SELECT由于 as 的隐式分组, 是合法t1,t2(t1,t2)。现在JOIN优先,所以ON子句的操作数是t2and t3。因为t1.i1不是任何一个操作数中的列,所以结果是Unknown column 't1.i1' in 'on clause'错误的。要允许处理连接,请将前两个表用括号显式分组,以便ON子句的操作数是(t1,t2)and t3

    SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);
    

    或者,避免使用逗号运算符,JOIN而是使用:

    SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);
    

    此更改也适用于将逗号运算符与INNER JOIN, CROSS JOIN,LEFT JOIN和混合的语句RIGHT JOIN,所有这些语句现在都比逗号运算符具有更高的优先级。

于 2013-07-22T10:46:05.973 回答