SQL过滤器可查找状态不同的重复产品名称

我正在尝试为客户选择归档为“重复”或“归档”的不同产品。

select a.customer_id,a.type -- reccuring/on file,b.name as product_name,from table.a as a
join table.c as c on c.id = a.c_id
join table.b as b on b.id = c.b_id
where a.current_state <> 'canceled'
order by 1

我的输出如下:

id/type/product_name 
<br> 111 on_file someProduct
<br> 111 recurring someOtherProduct
<br> 112 on_file someProduct
<br> 112 recurring someProduct 

最终目标是仅选择具有相同产品名称且类型均为on_file和重复出现的客户。我尝试对它们进行排名,但是即使它们具有相同的名称,也具有不同的产品ID

lisheng1987 回答:SQL过滤器可查找状态不同的重复产品名称

我想您需要以下查询

    Select id,product_name,count(distinct type) from
    Table where type in
     ('on_file','recurring') group by id,Product_name
     having 
    count(distinct type)=2
本文链接:https://www.f2er.com/3150284.html

大家都在问