Suppose we have the following table named stock_item in which the column quantity has duplicate values i.e. for the item names "Notebook" and "Pencil" the "Quantity" column has duplicate value "40" ", for the item "Shirt", the column "Quantity" has duplicate values, the triple value of "Shoes" and "Pants" 29 is held by the "Quantity" column as shown in the table.
mysql> Select * from stock_item; +------------+----------+ | item_name |quantity | +------------+----------+ | Calculator | 89 | | Notebooks | 40 | | Pencil | 40 | | Pens | 32 | | Shirts | 29 | | Shoes | 29 | | Trousers | 29 | +------------+----------+ 7 rows in set (0.00 sec)
Now with the help of the following query we can find the total number of duplicate/triple values in the "Quantity" column.
mysql> Select COUNT(quantity) AS duplicate_triplicate -> from stock_item -> group by quantity having duplicate_triplicate> 1; +----------------------+ | duplicate_triplicate | +----------------------+ | 3 | | 2 | +----------------------+ 2 rows in set (0.00 sec)
The above results show that the "quantity" column has a value repeated three times and a value repeated twice.
The above is the detailed content of How can we count records in a MySQL table whose columns contain duplicate/triple data?. For more information, please follow other related articles on the PHP Chinese website!