SELECT orderNumber, FORMAT(SUM(quantityOrdered * priceEach),2) total FROM orderdetails GROUP BY orderNumber ORDER BY SUM(quantityOrdered * priceEach) DESC; 执行上面查询语句,得到以下结果 -
SELECT orderNumber, FORMAT(SUM(quantityOrdered * priceEach),2) FROM orderdetails GROUP BY orderNumber HAVING SUM(quantityOrdered * priceEach) > 60000 ORDER BY SUM(quantityOrdered * priceEach); 执行上面查询语句,得到以下结果 -
MySQL SUM与LIMIT
假设您想要计算products表中前十名最昂贵的产品的总和,可以提出以下查询:
SELECT SUM(buyprice) FROM products ORDER BY buyprice DESC LIMIT 10; 执行上面查询语句,得到以下结果 -