现在有一条a的数据, 我想查询出来以a为中心,a前面两天数据和a后面两条数据结合起来的5条数据。要怎么实现呢。?
解决方案 »
- 求一条统计的sql语句
- 如何计算一个mysql进程最大占用的资源呢?
- SQL慢查询优化
- 怎样在存储过程里面执行SQL语句!!
- 一个搞笑的问题,select * from sinodictionary where Chinese='我';
- 我有一个Jive_mysql.sql文件,不懂在mysql中怎么用?
- 请问怎么让记录重新排序啊?
- jsp+Mysql 存储中文为何是滥码??
- mysql数据引擎修改后重新初始化数据库mysql库下表为何还是MYISAM
- 2个表关联 同时order的问题
- ◆救命啊!mysql误删数据恢复◆
- 本机没有mysql数据库,怎样在本机对另一台装有MySql的自己上的数据库进行操作呢
贴建表及插入记录的SQL,及要求结果出来看看
2 jeffery pingpang
3 lucy food
5 dave water
6 jack dddd
7 sunny test比如这六条数据 我知道了 name 为 dave 的人, 那么我想找出来jeffery,lucy,dave,jack,sunny这五条数据, 如果以lucy为条件,那么找出来make,jeffery,lucy,dave,jack这五条数据。也就是一条件为中心的五条数据。
union all
(select * from table1 where id<(select id from table1 where name='dave') order by id limit 2)
(select * from table1 where id>2009 order by id limit 2)
union all
(select * from table1 where id<=2009 order by id limit 3)
UNION ALL
(SELECT `year` FROM wt_brandnotes WHERE `year`>=2009 GROUP BY `year` ORDER BY `year` LIMIT 3)
结果
2008
2007
2009
2010
2012只是 2008 和 2007 顺序不对了
union all
select id from tb where id>2008 order by id limit 2;
(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`