开发者

Android SQLite: Can I consolidate these four SQLite queries into one?

They're all querying the same table, one SELECTs number of results and the other set of queries SELECTs the minimum.

Can this be conslidated into a single query

      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'开发者_开发百科");


You are probably looking for the GROUP BY function:

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

This will give you the COUNT(*) and MIN(price) for all distinct values found in subCondition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜