0

我有一个表,其中某个列的数据有时会丢失,在这种情况下只有一个破折号。

但是由于还有另一列是唯一的,因此可以从其他行中推断出丢失的数据。

换句话说,我有这样的事情:

独特的型号 制作者 利润
abcd1234 - 56
zgh675 Y公司 40
abcd1234 X公司 3
zgh675 - 10
abcd1234 X公司 1

我可以使用哪个查询来自动到达以下内容(Maker 列表是动态的,但每个模型只能访问其中一个):

独特的型号 制作者 利润
abcd1234 X公司 60
zgh675 Y公司 50

?

4

1 回答 1

0

You may aggregate by unique model and then take the MAX value of the maker, along with the sum of the profit:

SELECT model, MAX(maker) AS maker, SUM(profit) AS profit
FROM yourTable
GROUP BY model;

This approach should work assuming that each model only has one unique non NULL value.

于 2021-03-06T10:58:29.113 回答