我有一个表,其中的项目具有名为add_time的日期时间列
我想这样做:
例如,在id为10的元素之前添加5个元素。
我只看到一种方法,这里只是mysql返回零行。
SELECT i.*
FROM `image` AS `i`
LEFT JOIN `image` AS `i2` ON i.id = i2.id
WHERE i2.id =1317
AND i.`add_date` < i2.`add_date`
ORDER BY i.add_date DESC
LIMIT 0 , 5
答案 0 :(得分:1)
select *
from image
where date_add < (select date_add from image where id = 10)
order by date_add desc
limit 5