Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-20 21:49:02
forward
1271 people have browsed it

我们如何计算 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!