我们如何在MySQL表的列中计算多个唯一值?
通过使用DISTINCT关键字和列名作为COUNT()
函数的参数,我们可以计算列中唯一值的数量。语法如下-
SELECT COUNT(DISTINCT Col_name) FROM table_name;
示例
假设我们有下表
mysql> Select * from tender;+----------+--------------+--------------+-------+
| clientid | client_Fname | Client_Lname | value |
+----------+--------------+--------------+-------+
| 100 | Mohan | Kumar | 60000 |
| 101 | Sohan | Singh | 50000 |
| 101 | Somil | Rattan | 55000 |
| 103 | Gaurav | Kumar | 75000 |
| 103 | Rahul | Singh | 63000 |
+----------+--------------+--------------+-------+
5 rows in set (0.00 sec)
现在,如果我们要计算名为“ clientid”的列中唯一值的总数,则可以在以下查询的帮助下完成:
mysql> Select COUNT(DISTINCT Clientid) from tender;+--------------------------+
| COUNT(DISTINCT Clientid) |
+--------------------------+
| 3 |
+--------------------------+
1 row in set (0.00 sec)
而且,如果我们要计算名为“ Client_Lname”的列中唯一值的总数,则可以在以下查询的帮助下完成:
mysql> Select COUNT(DISTINCT Client_Lname) from tender;+------------------------------+
| COUNT(DISTINCT Client_Lname) |
+------------------------------+
| 3 |
+------------------------------+
1 row in set (0.00 sec)
以上是 我们如何在MySQL表的列中计算多个唯一值? 的全部内容, 来源链接: utcz.com/z/350186.html