我想用与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。
答案 0 :(得分:3)
尝试
SELECT COUNT(DISTINCT id_purchase) as Total FROM pur_supp WHERE pn = '02N64073'