如何计算重复数据的数量?

时间:2019-05-15 07:20:39

标签: mysql

我想用与ID相同的pn来计算数据。这是我的示例数据:

id_form                  id_purchase               pn
PUR3-20190515022552     PUR-20190515022552  02N64073
PUR2-20190515022552     PUR-20190515022552  02N64073
PUR1-20190515022552     PUR-20190515022552  02N64073

这是我的代码:

SELECT COUNT(*) as Total FROM pur_supp WHERE pn = '02N64073' GROUP BY id_purchase 

运行代码时,总数仍为3,但我希望总数为1。

1 个答案:

答案 0 :(得分:3)

尝试

 SELECT COUNT(DISTINCT id_purchase) as Total FROM pur_supp WHERE pn = '02N64073'