我正在使用 SQLite 数据库浏览器。
表:测试测试有一个单列“单词”,其中一些值如下所示:
Words
--------
apple
pen
xerox
notebook
toys
zoo
stars
apes
编写一个 sql 查询(应该在 SQLite 数据库浏览器中执行)以选择“xerox”和“stars”之间的单词以及从“pen”到猿的单词。
这可能是一种选择:
SELECT * FROM test
WHERE ROWID BETWEEN
(SELECT ROWID FROM test WHERE words = 'xerox') + 1
AND
(SELECT ROWID FROM test WHERE words = 'stars') - 1
UNION ALL
SELECT '---'
UNION ALL
SELECT * FROM test
WHERE ROWID BETWEEN
(SELECT ROWID FROM test WHERE words = 'pen')
AND
(SELECT ROWID FROM test WHERE words = 'apes');
select *
from Test
where Words between 'stars' and 'xerox'
or Words between 'apes' and 'pen'
请注意,第一个参数between
应该小于第二个。所以在字母表中的'stars'
'xerox because
's comes before
x`之前。