由desc命令的mysql错误

时间:2017-02-07 04:23:00

标签: mysql

这是我的查询。当我在此查询中通过desc添加订单时会收到错误请帮助我。

SELECT *
FROM
  (SELECT package_details.*,
          r.state AS source_name,
          d.state AS dest_name
   FROM (`package_details`)
   LEFT JOIN country_state_city r ON r.id=package_details.region_id
   LEFT JOIN country_state_city d ON d.id=package_details.destination_id
   WHERE `package_availability_type` = 'all'
     AND `admin_status` = 'ACTIVE'
     AND `status` = 'ACTIVE'
     AND (package_name LIKE '%Istanbul%'
          OR routes LIKE '%Istanbul%'
          OR r.state LIKE '%Istanbul%'
          OR d.state LIKE '%Istanbul%')
     AND
   ORDER BY `package_price` DESC
   UNION ALL SELECT package_details.*,
                    r.state AS source_name,
                    d.state AS dest_name
   FROM (`package_details`)
   LEFT JOIN country_state_city r ON r.id=package_details.region_id
   LEFT JOIN country_state_city d ON d.id=package_details.destination_id
   WHERE `package_availability_type` ='range'
     AND `admin_status` = 'ACTIVE'
     AND `status` = 'ACTIVE'
     AND `to_date` >= '2017-02-07'
     AND (package_name LIKE '%Istanbul%'
          OR routes LIKE '%Istanbul%'
          OR r.state LIKE '%Istanbul%'
          OR d.state LIKE '%Istanbul%')
     AND
   ORDER BY `package_price` DESC) AS dt LIMIT 0,100

错误: 您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在'ORDER BY package_price DESC UNION ALL SELECT package_details附近使用正确的语法。*,r.state AS sour'在第1行

1 个答案:

答案 0 :(得分:0)

在Order By Clause之前移除AND

 AND
   ORDER BY `package_price` DESC