我有一张这样的桌子:
uploadFiles(): void {
const dialogRef = this.dialog.open(AddNewFilesOrImagesComponent, {
panelClass: 'myClass',
});
}
我想用sum(columnC)查找不同的columnA和columnB 该表是ORDER BY SUM(columnC)DESC。
.myClass {
max-height: 95%;
width: 620px;
overflow-y: auto;
{
当我尝试
importer exporter quantity
A D 0.9
A B 0.9
A B 0.1
B E 9.4
B E 8.9
B D 9.4
C P 9.0
C V 1.0
C P 0.9
MYsql显示的表不是columnA和columnB不同,实际上,它显示了重复的columnA和columnB,并且没有将columnC加起来。
答案 0 :(得分:2)
尝试一下:
SELECT importer,
exporter,
SUM(quantity) AS sum_quantity
FROM tablename
GROUP BY importer,
exporter
ORDER BY sum_quantity DESC;
答案 1 :(得分:0)
尝试如下
SELECT
IMPORTER, EXPORTER, sum(QUANTITY)
FROM Tablename group by IMPORTER, EXPORTER
答案 2 :(得分:0)
@GordonLinoff暗示,您需要的是GROUP BY
查询
SELECT
IMPORTER,
EXPORTER,
SUM(QUANTITY)
FROM Tablename
GROUP BY
IMPORTER,
EXPORTER
ORDER BY
SUM(QUANTITY) DESC;
答案 3 :(得分:0)
这是基本的GROUP BY:
SELECT
IMPORTER, EXPORTER, SUM(QUANTITY) AS SUMQUANTITY
FROM Tablename
GROUP BY IMPORTER, EXPORTER
ORDER BY SUMQUANTITY DESC;