【发布时间】:2018-03-24 00:39:30
【问题描述】:
在下表中,我需要选择重复记录,其中除特定周的客户类型和价格外,所有列都是重复的。
例如
Week Customer Product Customer Type Price
1 Alex Cycle Consumer 100
1 Alex Cycle Reseller 101
2 John Motor Consumer 200
3 John Motor Consumer 200
3 John Motor Reseller 201
我正在使用以下查询,但此查询并未显示两种客户类型,它仅显示组合的消费者计数 (*)。
select Week, Customer, product, count(distinct Customer Type)
from table
group by Week, Customer, product
having count(distinct Customer Type) > 1
我想看到下面的结果,它显示了重复的值,而不仅仅是重复行的计数(*)。我试图查看在特定周内分配给产品的多个客户类型的客户,同时向我显示所有列。价格不同也没关系。
Week Customer Product Customer Type Price
1 Alex Cycle Consumer 100
1 Alex Cycle Reseller 101
3 John Motor Consumer 200
3 John Motor Reseller 201
谢谢
沙基
【问题讨论】:
-
您正在使用哪个RDBMS,请标记它。
-
请添加一个标签,告诉我们您使用哪个数据库。 “SQL”不足以告诉使用建议的选项和语法。
-
如果您的数据库支持,您似乎需要 row_number