让我们首先创建一个表-
mysql> create table DemoTable -> ( -> UserName varchar(20), -> UserType ENUM('New User','Registered User') -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris','New User'); mysql> insert into DemoTable values('David','New User'); mysql> insert into DemoTable values('Mike','Registered User'); mysql> insert into DemoTable values('Sam','New User');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable;
这将产生以下输出-
+----------+-----------------+ | UserName | UserType | +----------+-----------------+ | Chris | New User | | David | New User | | Mike | Registered User | | Sam | New User | +----------+-----------------+ 4 rows in set (0.00 sec)
这是获取不同类型用户数量的查询-
mysql> select count(*),UserType from DemoTable group by UserType;
+----------+-----------------+ | count(*) | UserType | +----------+-----------------+ | 3 | New User | | 1 | Registered User | +----------+-----------------+ 2 rows in set (0.00 sec)