以前是在Set中来做
现在可以在数据库中来做了
O(∩_∩)O哈哈~,是不是很爽啊?
表:
mysql> select userlevel,username from users;
+-----------+----------+
| userlevel | username |
+-----------+----------+
| admin | cdliang |
| service | bobo |
| user | caocao |
| user | yongyong |
| service | zhouzhou |
+-----------+----------+
5 rows in set (0.00 sec)
目的:查询不重复的数目
1.distinct
mysql> select count(distinct userlevel)权限数目 from users;
+----------+
| 权限数目 |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)
2.使用嵌套查询
mysql> select count(*)权限数目 from (select distinct userlevel from users) t;
+----------+
| 权限数目 |
+----------+
| 3 |
+----------+
1 row in set (0.00 sec)