mysql 查询左右数据,该如何处理

mysql 查询左右数据

现在有一条a的数据, 我想查询出来以a为中心,a前面两天数据和a后面两条数据结合起来的5条数据。要怎么实现呢。?



(select * from table1 where id>=(select id from table1 where name=’dave’) order by id limit 3)

union all

(select * from table1 where id<(select id from table1 where name=’dave’) order by id limit 2)




select * from (

(SELECT `year` FROM wt_brandnotes WHERE `year`<2009 GROUP BY `year` ORDER BY `year` DESC LIMIT 2)

UNION ALL

(SELECT `year` FROM wt_brandnotes WHERE `year`>=2009 GROUP BY `year` ORDER BY `year` LIMIT 3)

) a order by `year`

mysql 查询左右数据,该如何处理

相关文章:

你感兴趣的文章:

标签云: