How does SQL count and remove duplicate data records? If the record is duplicated without statistics, it will be counted as 0, and only those that are not duplicated will be counted.

as mentioned above, I want to count the number of records in the database. If a field is required to repeat, the count is 0. For example: a database of car sales invoices, in which there is a frame number field referred to as CJHM. I want to count the number of cars sold that month, but remove the same record as CJHM. That is, if two records have the same CJHM, neither record is counted. For example, the following table:
ID CJHM XSSJ
1 ljh908 2018-06-07
2 ljh908 2018-06-07
3 33ert78 2018-06-10
4 9087jh1 2018-06-23

Statistical results are required to be shown as: 2, that is, two records with the same CJHM are removed

May.22,2021

SELECT COUNT(1)
FROM (
    SELECT 1
    FROM `car`
    GROUP BY `CJHM`
    HAVING COUNT(1)=1
) a;

without considering efficiency:
select count (CJHM) from CarTable a
where (a.CJHM) not in (select CJHM from CarTable group by CJHM having count (*) > 1)

Menu