我有一张桌子:
Invoice| Colour | Type
In_001 | Red | D
In_001 | Red | D
In_001 | Yellow | E
In_002 | Red | H
我希望得到的结果是整理出发票数量超过
购买了两件商品并显示数量。
见下文,预期结果:
Invoice | Colour | Type | Count
In_001 | Red | D | 2
In_001 | Yellow | E | 1
备注:由于仅购买了一项,因此不包含In_002。
我尝试了以下命令:
select invoice, colour, type, count(invoice) from t
group by invoice,colour,type
having count(invoice)>1;
结果是:
Invoice | Colour | Type | Count
In_001 | Red | D | 2
请帮忙。
最佳答案
分组依据是所有三个发票,颜色和类型。因此结果只会是这样。
我们可以尝试下面的查询来实现它:
select invoice,colour,type,count(invoice) from t where invoice in
(select invoice from t group by invoice having count(invoice) >1)
group by invoice,colour,type
关于hadoop - 发票,颜色,类型,数量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33141592/