我正在使用下面的语句按月对结果进行分组以给出总价,但是我还需要知道已经分组了多少行,但前提是价格高于一定数量。
"SELECT SUM(price) FROM table GROUP BY month";
采用SUM with CASE
SELECT SUM(price) totalPrice,
SUM(CASE WHEN price > x THEN 1 ELSE 0 END) totalRows
FROM table
GROUP BY month
X
价格的价值在哪里
一种选择是使用COUNT
and CASE
:
SELECT SUM(price), COUNT(CASE WHEN Price > 100 THEN 1 END)
FROM table
GROUP BY month