作者arrack (艾瑞克)
看板Database
标题Re: [SQL ] 选取特定主键跟其下一笔之外的资料
时间Wed Jun 25 17:02:47 2008
※ 引述《JYHuang (夏天到了,冷不起来了说)》之铭言:
: 感谢~
: 不过查询结果似乎还是没有排除 id=10 跟其下一笔
: 设原资料有 id 10,11,12三笔的话,欲查询 id in(10,11)以外的
: 我们下的查询都是显示
: id .....
: 10 ... <-- right join
: 11 ... <-- 合并进来的资料? @@
: 12 ...
: 12 ... <--
select news.* from news,
(select id from news where id=10 order by id limit 1 ) as a ,
(select id from news where id>10 order by id limit 1 ) as b
where news.id<>a.id and news.id<>b.id order by news.id
但是我只能说 效能惨不睹:)
查询前=>993 总计, 查询需时 0.0095 秒
查询後=>991 总计, 查询需时 0.4377 秒
PS.记得把news改成你的tablename
--
Best Regards,
Arrack Tseng
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.126.63.16
※ 编辑: arrack 来自: 59.126.63.16 (06/25 17:04)
※ 编辑: arrack 来自: 59.126.63.16 (06/25 17:05)