对应的Mysql查询的Sqlite查询语法

时间:2012-06-23 08:53:27

标签: android mysql sqlite

请帮我找到以下查询的sqlite等价物。经常尝试搜索。

    SET @rownum := 0;
SELECT * FROM (
SELECT @rownum := @rownum+1 AS rank, id
FROM tbl_flight
ORDER BY id DESC
) AS tbl_flight WHERE id = 2

1 个答案:

答案 0 :(得分:2)

您不能在单个查询中执行此操作,但可以使用临时表和每个表的rowid属性:

http://sqlfiddle.com/#!5/f0a1b/8(你不能两次运行小提琴,你必须先重建架构然后再运行它)

DROP TABLE IF EXISTS tmp;

CREATE TEMPORARY TABLE tmp AS 
  SELECT id
  FROM tbl_flight
  ORDER BY id DESC;

SELECT tmp.rowid AS rank, tmp.id FROM tmp WHERE id=2;