执行以下语句会返回错误:
SELECT co.id,co.user_id,co.cat_id,co.offer_name,co.cost,u.shop_name, CASE WHEN buy >= get THEN buy
else get END as buy FROM createdoffers co INNER JOIN categories ct ON ct.id=co.cat_id INNER JOIN users u ON u.id=co.user_id
WHERE ct.Head_id='$head' AND ct.id=co.cat_id ORDER BY co.buy DESC LIMIT 1
MySQL返回:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'get THEN buy
else get END as buy FROM createdoffers co INNER JOIN cate' at line 1
我找不到错误,请解释此查询的错误。
答案 0 :(得分:0)
get是一个关键字。用
逃避它SELECT co.id,co.user_id,co.cat_id,co.offer_name,co.cost,u.shop_name,
CASE WHEN buy >= `get` THEN buy else `get` END as buy
FROM createdoffers co INNER JOIN categories ct ON ct.id=co.cat_id INNER JOIN users u ON u.id=co.user_id WHERE ct.Head_id='$head' AND ct.id=co.cat_id ORDER BY co.buy DESC LIMIT 1