首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

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

2012-03-05 
mysql 查询左右数据现在有一条a的数据, 我想查询出来以a为中心,a前面两天数据和a后面两条数据结合起来的5

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`

热点排行