从MySQL中声明为BIGINT类型的电话号码的列中获取唯一电话号码的计数

为此,可以COUNT()与DISTINCT一起使用。该COUNT()方法是计数的记录。但是,DISTINCT返回不同的记录,而COUNT()方法对那些唯一的记录进行计数。让我们首先创建一个表-

mysql> create table DemoTable
(
   PhoneNumber bigint
);

使用插入命令在表中插入一些记录-

mysql> insert into DemoTable values(8567789898);
mysql> insert into DemoTable values(8567789898);
mysql> insert into DemoTable values(9876564534);
mysql> insert into DemoTable values(9087896545);
mysql> insert into DemoTable values(7656456589);
mysql> insert into DemoTable values(9876564534);
mysql> insert into DemoTable values(9087896545);

使用select语句显示表中的所有记录-

mysql> select *from DemoTable;

这将产生以下输出-

+-------------+
| PhoneNumber |
+-------------+
| 8567789898  |
| 8567789898  |
| 9876564534  |
| 9087896545  |
| 7656456589  |
| 9876564534  |
| 9087896545  |
+-------------+
7 rows in set (0.00 sec)

以下是查询以从具有号码的列中计算唯一号码-

mysql> select count(distinct PhoneNumber) AS UniquePhoneNumber from DemoTable;

这将产生以下输出-

+-------------------+
| UniquePhoneNumber |
+-------------------+
|                 4 |
+-------------------+
1 row in set (0.00 sec)