SQL查询“查找产生最多收入的文章?”

时间:2012-05-14 07:38:01

标签: mysql sql

我想创建一个SQL查询,向我展示产生最多收入的文章。 (在商店里)

    Table = orderrader

   rownumber    articlenumber   ordernumber price   amount
   1            11              1           8624    3
   2            6               1           4794    2
   3            17              1           8755    3
   4            1               1           7803    1
   5            16              1           8987    3
   6            10              1           4575    3
   7            4               1           8747    1
   8            15              1           5439    3
   9            11              2           8624    3
   10           1               2           7803    1

4 个答案:

答案 0 :(得分:2)

以下sql语句将只返回一个带有最大收入的文章编号。

Select  articlenumber, sum(price*amount) as totalincome
from orderrader
group by articlenumber 
order by sum(price*amount) desc LIMIT 1

答案 1 :(得分:1)

SELECT articlenumber
FROM orderrader
WHERE (price * amount) = (SELECT MAX(price * amount) FROM orderrader)

这应该可以解决问题,我在我自己的数据库上查看了它。它只给出价格最高的那个*金额

答案 2 :(得分:1)

SELECT articlenumber, SUM(price*amount) AS income
FROM table
GROUP BY articlenumber
ORDER BY income DESC

答案 3 :(得分:0)

select articlenumber, sum(price*amount) as s from orderrader group by articlenumber order by s desc;