检查此查询语法

时间:2015-07-30 10:59:20

标签: mysql sql database

当我运行此查询时,它会出现此错误

  

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'LEFT JOIN预订rs on r.restaurant_id = rs.restaurant_id附近使用正确的语法                    '第7行

,查询是

SELECT r.`restaurant_id`,r.`restaurant_name`,r.`capacity`,rs.`start_time`,rs.`end_time`,rs.`people`,rs.`date`,r.`capacity` - SUM(rs.`people`) AS available
            FROM `restaurant` r,


                LEFT JOIN reservation rs ON r.restaurant_id = rs.restaurant_id
               AND <'2015-07-30'> = rs.`date`
              AND <'2:00' >= rs.`end_time`
              AND <'3:00'> = rs.`start_time`
            GROUP BY r.`restaurant_id`

请告诉我我错在哪里

2 个答案:

答案 0 :(得分:1)

我修改了你的sql。在离开之前加入他们的是逗号,请删除它。

SELECT 
r.restaurant_id,r.restaurant_name,r.capacity,rs.start_time,rs.end_time,rs.people,rs.date,r.capacity - SUM(rs.people) AS available FROM restaurant r

                LEFT JOIN reservation rs ON r.restaurant_id = rs.restaurant_id
               AND '2015-07-30' = rs.`date`
              AND '2:00' = rs.`end_time`
              AND '3:00' = rs.`start_time`
            GROUP BY r.`restaurant_id`

谢谢。

答案 1 :(得分:0)

我没有长时间使用MySQL,只有PL / SQL,但我不认为,“FROM restaurant r中有逗号”,试试“FROM restaurant r”