他们都在查询同一个表,一个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'");
答案 0 :(得分:1)
您可能正在寻找GROUP BY功能:
SELECT subCondition,COUNT(*),MIN(price) FROM Offers GROUP BY subCondition;
这将为subCondition
中找到的所有不同值提供COUNT(*)和MIN(价格)。