distinct 去除重复

mysql> alter table one add column rtime int;    //添加一个时间字段 
Query OK, 8 rows affected (0.01 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> desc one;
+----------+------------------+------+-----+---------+----------------+
| Field    | Type             | Null | Key | Default | Extra          |
+----------+------------------+------+-----+---------+----------------+
| id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| username | varchar(50)      | NO   |     | NULL    |                |
| password | varchar(32)      | NO   |     | NULL    |                |
| age      | int(11)          | NO   |     | NULL    |                |
| rtime    | int(11)          | YES  |     | NULL    |                |
+----------+------------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql> truncate one;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into one (username,password,age,rtime) values('zhang1',123,25,201
),('zhang2',123,24,2018);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into one (username,password,age,rtime) values('zhang3',123,24,201
),('zhang4',123,24,2018);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into one (username,password,age,rtime) values('zhang4',123,24,201
),('zhang6',123,23,2018);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into one (username,password,age,rtime) values('zhang7',123,21,201
),('zhang8',123,22,2018);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0       //两条插入
 
mysql> select * from one;
+----+----------+----------+-----+-------+
| id | username | password | age | rtime |
+----+----------+----------+-----+-------+
|  1 | zhang1   | 123      |  25 |  2018 |
|  2 | zhang2   | 123      |  24 |  2018 |
|  3 | zhang3   | 123      |  24 |  2018 |
|  4 | zhang4   | 123      |  24 |  2018 |
|  5 | zhang4   | 123      |  24 |  2018 |
|  6 | zhang6   | 123      |  23 |  2018 |
|  7 | zhang7   | 123      |  21 |  2018 |
|  8 | zhang8   | 123      |  22 |  2018 |
+----+----------+----------+-----+-------+
8 rows in set (0.00 sec)

mysql> select age from one;                   //C查询出one表所有年龄         
+-----+
| age |
+-----+
|  25 |
|  24 |
|  24 |
|  24 |
|  24 |
|  23 |
|  21 |
|  22 |
+-----+
8 rows in set (0.00 sec)
                                            //distinct 去重 
mysql> select distinct age from one;        //查询出所有用户的年龄段去重 
+-----+
| age |
+-----+
|  25 |
|  24 |
|  23 |
|  21 |
|  22 |
+-----+
5 rows in set (0.00 sec)
                                        //all 全部 
mysql> select all age from one;         //查询所有用户的所有年龄字段 (默认为all)
+-----+
| age |
+-----+
|  25 |
|  24 |
|  24 |
|  24 |
|  24 |
|  23 |
|  21 |
|  22 |
+-----+
8 rows in set (0.00 sec) 
 
mysql> select id,username,age from one;   //查询出所有id username age 字段 内容
+----+----------+-----+
| id | username | age |
+----+----------+-----+
|  1 | zhang1   |  25 |
|  2 | zhang2   |  24 |
|  3 | zhang3   |  24 |
|  4 | zhang4   |  24 |
|  5 | zhang4   |  24 |
|  6 | zhang6   |  23 |
|  7 | zhang7   |  21 |
|  8 | zhang8   |  22 |
+----+----------+-----+
8 rows in set (0.00 sec)   

             

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值