求助 mysql 查询的一个问题 急需
我的数据库模式是 id value 2个字段 我要求 查询 出来 满足 字段=一个值的所有前后10条数据(这个整个数据有几十万条)。
作者: runin_zty 发布时间: 2011-05-25
表中有无唯一标识的字段?比如ID
作者: WWWWA 发布时间: 2011-05-25
SQL code
select * from tb where value='xx' order by id asc limit 10 union all select * from tb where value='xx' order by id desc limit 10
作者: rucypli 发布时间: 2011-05-25
引用 2 楼 rucypli 的回复:
SQL code
select * from tb where value='xx' order by id asc limit 10
union all
select * from tb where value='xx' order by id desc limit 10
正解
SQL code
select * from tb where value='xx' order by id asc limit 10
union all
select * from tb where value='xx' order by id desc limit 10
作者: ACMAIN_CHM 发布时间: 2011-05-25
SQL code
elect * from tb where abs(id-'一个值')<=10 and id <>'一个值'
作者: vipper23 发布时间: 2011-05-25
引用 2 楼 rucypli 的回复:
SQL code
select * from tb where value='xx' order by id asc limit 10
union all
select * from tb where value='xx' order by id desc limit 10
SQL code
select * from tb where value='xx' order by id asc limit 10
union all
select * from tb where value='xx' order by id desc limit 10
这个不是 我的要求的 。
我要求的是 比如说 我 输入的 是 110 这个 value 我要的是 所有 110这个值得 前后 10条数据 不要这个 110 数据
作者: runin_zty 发布时间: 2011-05-25