-2

我正在使用 SQLite 数据库浏览器。

表:测试测试有一个单列“单词”,其中一些值如下所示:

   Words
   --------
   apple
   pen
   xerox
   notebook
   toys
   zoo
   stars
   apes

编写一个 sql 查询(应该在 SQLite 数据库浏览器中执行)以选择“xerox”和“stars”之间的单词以及从“pen”到猿的单词。

4

2 回答 2

1

这可能是一种选择:

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');
于 2013-08-08T11:18:05.480 回答
0
select  *
from    Test
where   Words between 'stars' and 'xerox'
        or Words between 'apes' and 'pen'

请注意,第一个参数between应该小于第二个。所以在字母表中的'stars''xerox because's comes beforex`之前。

于 2013-08-07T23:16:50.597 回答