mysql - SQL 查询 "Find the article that has generated most income?"

标签 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

最佳答案

以下 sql 语句将只返回一个具有最大收入的商品编号。

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

关于mysql - SQL 查询 "Find the article that has generated most income?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10579221/

相关文章:

mysql - 如何在phpmyadmin中调用mysql函数?

python - Mysqldb 和 Python KeyError 处理

sql - PostgreSQL:删除子查询返回的行

mysql - 从具有简单输出的许多表中检索数据

mysql - 如何在mysql中获取首字母大写小写的数据?

sql - SSIS 无法在直接输入查询中使用 LIKE 分配给变量

mysql - 无法使用 hibernate 查询从多个表中复制数据并插入到一个表中

非事件用户时的 PHP 邮件

php - CodeIgniter 中带有 if 语句的两个插入查询

php - MySQL Update只会更新查询中指定的某些字段