This question already has answers here:
Mixing ANSI 1992 JOINs and COMMAs in a query
                                
                                    (2个答案)
                                
                        
                                6年前关闭。
            
                    
我试图从两张桌子下面显示价格低廉的酒店客房(低价客房的酒店,无需显示该酒店的其他客房)。
但是我收到错误“在子句中不知道列column_name”。请检查我的查询

    SELECT  r.*,h.*
    FROM hotels_temp h,rooms_temp r
    INNER JOIN
    (
      SELECT
        hotel_code,MIN(amount) mincost
      FROM
        rooms_temp
      GROUP BY hotel_code
    ) m ON r.amount = m.mincost and h.hotel_code=r.hotel_code
    ORDER BY r.amount
    LIMIT 30


表名称:hotels_temp



表名称:rooms_temp

最佳答案

我可以通过以下查询自己解决此问题。

    SELECT * FROM hotels_temp
    INNER JOIN
    (
        SELECT  r.amount,r.hotel_code FROM rooms_temp r
        INNER JOIN
        (
            SELECT hotel_code,amount, MIN(amount) mincost FROM rooms_temp  GROUP BY hotel_code
        ) m ON
        r.amount = m.mincost GROUP BY r.hotel_code
    ) ht ON
    ht.hotel_code=hotels_temp.hotel_code LIMIT 0,30

关于mysql - 当我尝试加入两个表时,Mysql抛出“未知的列column_name in on子句”错误。 ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15003481/

10-09 23:05