我有一个相当长且复杂的查询,最终会产生如下结果:
item_id | shop_id | sold
5 3 0
5 3 1
5 3 1
8 4 0
8 6 1
8 9 0
然后我需要以某种方式SELECT item_id, COUNT(DISTINCT (shop_id)) FROM tableAbove GROUP BY item_id
获得:
item_id | number of shops that sell/have sold item
5 1
8 3
但是,我还需要为每件商品提供成功销售它的商店数量,所以像这样:
item_id | number of shops that have sold item
5 1
8 1
有谁知道我怎么能把它们放在一起在一个查询中给出
item_id | shops that sell item |number of shops that have sold item
5 1 1
8 3 1