Android SQLite:我可以将这四个SQLite查询合并为一个吗?

时间:2011-04-04 23:36:37

标签: sqlite

他们都在查询同一个表,一个SELECT数量的结果,另一组查询SELECT最小。

这可以合并为一个查询

      likeNewTotal = db.getSingleValue("SELECT COUNT(*) FROM Offers WHERE subCondition = 'likenew'");
   veryGoodTotal = db.getSingleValue("SELECT COUNT(*) FROM Offers WHERE subCondition  = 'verygood'");
 goodTotal = db.getSingleValue("SELECT COUNT(*) FROM Offers WHERE subCondition  = 'good'");
    acceptableTotal = db.getSingleValue("SELECT COUNT(*) FROM Offers WHERE subCondition  = 'acceptable'");

    likeNewLow = db.getSingleValue("SELECT MIN(price) FROM Offers WHERE subCondition = 'likenew'");
        veryGoodLow = db.getSingleValue("SELECT MIN(price) FROM Offers WHERE subCondition  = 'verygood'");
    goodLow = db.getSingleValue("SELECT MIN(price) FROM Offers WHERE subCondition  = 'good'");
    acceptableLow = db.getSingleValue("SELECT MIN(price) FROM Offers WHERE subCondition  = 'acceptable'");

1 个答案:

答案 0 :(得分:1)

您可能正在寻找GROUP BY功能:

SELECT subCondition,COUNT(*),MIN(price) FROM Offers GROUP BY subCondition;

这将为subCondition中找到的所有不同值提供COUNT(*)和MIN(价格)。