数据库
首页 > 数据库> > SQL再学习plus

SQL再学习plus

作者:互联网

DML

添加数据

代码实现

mysql>  select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 1    |
| he   | 2    | 2    |
+------+------+------+
2 rows in set (0.01 sec)

mysql> insert into stu(name,id,sex) values("小爽",1,"女");
Query OK, 1 row affected (0.01 sec)

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 1    |
| he   | 2    | 2    |
| 小爽 | 1    | 女   |
+------+------+------+
3 rows in set (0.01 sec)

修改数据

代码实现

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 2    |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.02 sec)

mysql> update stu set sex = "男" where name = "he";
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.00 sec)

删除数据

代码实现


mysql> select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| he   | 2    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
4 rows in set (0.00 sec)

mysql> delete from stu where name = "he";
Query OK, 1 row affected (0.01 sec)

mysql>  select * from stu;
+------+------+------+
| name | id   | sex  |
+------+------+------+
| xue  | 1    | 男   |
| 小爽 | 1    | 女   |
| 小程 | 2    | 男   |
+------+------+------+
3 rows in set (0.00 sec)

DQL

代码实现

mysql> select name , sex from stu;
+------+------+
| name | sex  |
+------+------+
| xue  | 男   |
| 小爽 | 女   |
| 小程 | 男   |
+------+------+
3 rows in set (0.00 sec)

代码实现


mysql> select distinct sex from stu;
+------+
| sex  |
+------+
| 男   |
| 女   |
+------+
2 rows in set (0.03 sec)

起别名
代码实现


mysql> select name as "姓名",sex "性别" from stu;
+------+------+
| 姓名 | 性别 |
+------+------+
| xue  | 男   |
| 小爽 | 女   |
| 小程 | 男   |
+------+------+
3 rows in set (0.00 sec)

标签:+------+------+------+,name,mysql,sex,学习,stu,sec,SQL,plus
来源: https://www.cnblogs.com/he-cheng/p/16023010.html