0

我想做一个 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

4 回答 4

2

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

Select  articlenumber, sum(price*amount) as totalincome
from orderrader
group by articlenumber 
order by sum(price*amount) desc LIMIT 1
于 2012-05-14T07:46:22.167 回答
1
SELECT articlenumber
FROM orderrader
WHERE (price * amount) = (SELECT MAX(price * amount) FROM orderrader)

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

于 2012-05-14T07:41:17.490 回答
1
SELECT articlenumber, SUM(price*amount) AS income
FROM table
GROUP BY articlenumber
ORDER BY income DESC
于 2012-05-14T07:41:25.407 回答
0
select articlenumber, sum(price*amount) as s from orderrader group by articlenumber order by s desc;
于 2012-05-14T07:40:44.010 回答