SQLite排除,但仍包含在LIMIT子句中

时间:2017-11-04 21:02:08

标签: android sqlite android-sqlite

我想做的是排除的结果仍然计入LIMIT条款。使用以下任何排除的结果不计入7个返回的结果。我怎样才能完成这样的事情?

"SELECT * FROM (SELECT * FROM DBNAME DATAS WHERE A01 <> '' ORDER BY DATETIME(A01Date) DESC LIMIT 7) TMP ORDER BY DATETIME(A01Date) ASC"

1 个答案:

答案 0 :(得分:0)

  

计算机科学中的所有问题都可以通过另一层次的间接来解决    - 大卫惠勒

要在WHERE之前应用LIMIT,请将其移动到单独的子查询中:

SELECT *
FROM (SELECT *
      FROM (SELECT *
            FROM DBName
            ORDER BY datetime(A01Date) DESC
            LIMIT 7)
      WHERE A01 <> '')
ORDER BY datetime(A01Date) ASC;

现在您可以合并两个最外层的查询:

SELECT *
FROM (SELECT *
      FROM DBName
      ORDER BY datetime(A01Date) DESC
      LIMIT 7)
WHERE A01 <> ''
ORDER BY datetime(A01Date) ASC;