-2

我有以下 MYSQL 语法,但是当我运行它时,检查 MYSQL 手册的语法是否正确时出错。

MYSQL 查询是:

SELECT `listings`.sid FROM listings 
        LEFT JOIN `listings_properties` `lp` ON `lp`.`object_sid` = `listings`.`sid` AND `lp`.`id` = \'ClosingDate\'
        WHERE (expiration_date < NOW() OR `lp`.`value` <= NOW()) AND active = 1
4

3 回答 3

1

尝试删除 '\'ClosingDate\' 上的两个反斜杠 () 来:

SELECT `listings`.sid FROM listings 
LEFT JOIN `listings_properties` `lp` 
   ON `lp`.`object_sid` = `listings`.`sid` 
   AND `lp`.`id` = 'ClosingDate'
WHERE (expiration_date < NOW() 
   OR `lp`.`value` <= NOW()) AND active = 1
于 2012-09-30T08:26:14.873 回答
1
SELECT a.`sid` FROM `listings` a LEFT JOIN `listings_properties` b 
ON (b.`object_sid` = a.`sid` AND b.`id` = 'ClosingDate')
WHERE (a.`expiration_date` < NOW() OR b.`value` <= NOW()) AND a.`active` = 1

没必要逃'

于 2012-09-30T08:26:26.773 回答
1

这是错误

LEFT JOIN `listings_properties` `lp` ON `lp`.`object_sid` = `listings`.`sid` AND `lp`.`id` = \'ClosingDate\'

应该

  LEFT JOIN `listings_properties` `lp` ON `lp`.`object_sid` = `listings`.`sid` AND `lp`.`id` = 'ClosingDate'

和整个查询

SELECT a.`sid` FROM `listings` a LEFT JOIN `listings_properties` b 
ON (b.`object_sid` = a.`sid` AND b.`id` = 'ClosingDate')
WHERE (a.`expiration_date` < NOW() OR b.`value` <= NOW()) AND a.`active` = 1
于 2012-09-30T08:27:11.890 回答