Select*fromstock_item;+------------+----------+|item_name |quantity |+------------+ ----------+|Calculator|89"/> Select*fromstock_item;+------------+----------+|item_name |quantity |+------------+ ----------+|Calculator|89">

Home >Database >Mysql Tutorial >How can we count records in a MySQL table whose columns contain duplicate/triple data?

How can we count records in a MySQL table whose columns contain duplicate/triple data?

WBOY
WBOYforward
2023-09-20 21:49:021332browse

我们如何计算 MySQL 表中列包含重复/三重数据的记录?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete