Re: [SQL ] 選取特定主鍵跟其下一筆之外的資料
※ 引述《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)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 7 篇):