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
.
精彩评论