此查询不适用于mysql v 5.7.18。
但是这个查询在过去的mysql版本(5.5.46)
中运行得很好SELECT car_id FROM (
SELECT car_id ,
CASE WHEN ( unix_timestamp(STR_TO_DATE( car_from, '%Y-%m-%d %H:%i:%s' )) > unix_timestamp(STR_TO_DATE( '2017-03-15 13:00', '%Y-%m-%d %H:%i:%s' ))
|| unix_timestamp(STR_TO_DATE( '2017-03-09 17:00', '%Y-%m-%d %H:%i:%s' )) > unix_timestamp(STR_TO_DATE( car_to , '%Y-%m-%d %H:%i:%s' ))
|| unix_timestamp(STR_TO_DATE( '2017-03-15 13:00', '%Y-%m-%d %H:%i:%s' )) < unix_timestamp(STR_TO_DATE( '2017-03-09 17:00', '%Y-%m-%d %H:%i:%s' ))
|| unix_timestamp(STR_TO_DATE( car_to, '%Y-%m-%d %H:%i:%s' )) < unix_timestamp(STR_TO_DATE( car_from, '%Y-%m-%d %H:%i:%s' ))
) THEN 0
ELSE 1 END as intersect_time
FROM car_booking_master
WHERE state = '1'
GROUP BY car_id
HAVING intersect_time = 1
) AS virtual
在新的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 'virtual
LIMIT 0, 25' at line 15
答案 0 :(得分:2)
mysql版本的问题是我正在使用的关键字&#34;虚拟&#34; 。 使用&#34; v&#34;代替&#34;虚拟&#34;查询工作正常
答案 1 :(得分:0)
如果您尝试为子查询添加别名,则应删除最后一行中的IF (@value < 0)
BEGIN
RAISERROR('Invalid parameter: @value cannot be less than zero', 18, 0)
RETURN
END
。