【发布时间】:2020-10-02 06:36:18
【问题描述】:
我有一张表说它有两列zip code and customer code。假设有多个customer code 具有相同的zipcode。我需要获取上述两列,其中一列包含唯一的邮政编码,第二列包含相应邮政编码的唯一客户代码的数量。
这里的问题是一个邮政编码可能有多个唯一客户(有点像一个客户可能不止一次去过同一个邮政编码的商店,但我需要将他们视为一个)
如何在SQLite 中做到这一点。我做了以下SQL query,我只得到一个zip code
select distinct(C.pin_code),count(distinct(C.customer_code)) from customers as C inner join Sales as S on S.customer_code=C.customer_code
输出是
我不知道这是怎么回事。如果您需要更多信息,请在 cmets 中告诉我。
【问题讨论】:
标签: mysql sql sqlite count distinct