本文介绍了如何(MySQL)乘以列,然后乘以总和行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张桌子:

id    |   payment_id   | quantity  |  unit cost
1           633             1            750
2           633             1            750
3           632             2            750
4           632             2            750

我需要的是:

payemnt_id  |   total
    633           1500
    632           3000

您也可以将其视为国家/地区,然后尝试查找每个国家/地区的总数.我确定有一些类似的教程,但STFW找不到.

You can also think of this as Countries and then you are trying to find the total for each Country. I was sure there were some tutorials like this but could not find by STFW.

推荐答案

您只需将公式(表达式)放在SUM中:

You can simply put the formula (expression) inside SUM:

SELECT payment_id, SUM(`unit cost` * quantity) AS total
FROM myTable
GROUP BY payment_id

这篇关于如何(MySQL)乘以列,然后乘以总和行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 07:00