我有一个简单的表 CREATE TABLE MyTable (MyText TEXT UNIQUE ON CONFLICT REPLACE); 我有一个SELECT语句,它按创建时的降序返回表行: SELECT MyText FROM MyTable ORDER BY rowid DESC; 比如说,它返回
WITH SortedTable AS (
SELECT row_number() OVER (ORDER BY rowid DESC) AS RowNum,
MyText
FROM MyTable
)
SELECT RowNum
FROM SortedTable
WHERE MyText = 'C';
或者这个一行的版本: SELECT RowNum FROM (SELECT row_number() OVER (ORDER BY rowid DESC) AS RowNum, MyText FROM MyTable) WHERE MyText = 'C';
1条答案
按热度按时间pod7payv1#
我和朋友RaptorX聊天时得到了答案:
或者这个一行的版本:
SELECT RowNum FROM (SELECT row_number() OVER (ORDER BY rowid DESC) AS RowNum, MyText FROM MyTable) WHERE MyText = 'C';