码迷,mamicode.com
首页 > 数据库 > 详细

程序媛计划——mysql 插入、查找、修改、删除数据

时间:2017-09-08 23:58:23      阅读:358      评论:0      收藏:0      [点我收藏+]

标签:计划   sql   exist   not   cat   duplicate   字段   rds   rem   

#插入数据

[mysql>create table if not exists exam_score(
..>id int(4) not null primary key auto_increment,
..>name char(20) not null,
   ..>score double(6,2));

#用多个list插入多行数据
[mysql> insert into exam_score values (1,Zhao,95.33),(2,Qian,94.33),(3,Sun,44.55),(4,Li,33.55); Query OK, 4 rows affected (0.01 sec) Records: 4 Duplicates: 0 Warnings: 0
#展示整张表 mysql
> select * from exam_score; +----+------+-------+ | id | name | score | +----+------+-------+ | 1 | Zhao | 95.33 | | 2 | Qian | 94.33 | | 3 | Sun | 44.55 | | 4 | Li | 33.55 | +----+------+-------+ 4 rows in set (0.00 sec)
mysql
> insert into exam_score values (5,Zhou,66.33),(6,Wu,99.32),(7,Zheng,33.2),(8,Wang,99.3); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0
#查询按照字段id在0到2之间的行数据 mysql
> select * from exam_score order by id limit 0,2; +----+------+-------+ | id | name | score | +----+------+-------+ | 1 | Zhao | 95.33 | | 2 | Qian | 94.33 | +----+------+-------+ 2 rows in set (0.00 sec)
#查询整张表中的前两行 mysql
> select * from exam_score limit 0,2; +----+------+-------+ | id | name | score | +----+------+-------+ | 1 | Zhao | 95.33 | | 2 | Qian | 94.33 | +----+------+-------+ 2 rows in set (0.00 sec)
#按照name字段升序显示整张表 mysql
> select * from exam_score order by name asc; +----+-------+-------+ | id | name | score | +----+-------+-------+ | 4 | Li | 33.55 | | 2 | Qian | 94.33 | | 3 | Sun | 44.55 | | 8 | Wang | 99.30 | | 6 | Wu | 99.32 | | 1 | Zhao | 95.33 | | 7 | Zheng | 33.20 | | 5 | Zhou | 66.33 | +----+-------+-------+ 8 rows in set (0.01 sec)
#按照name降序显示
mysql> select * from exam_score order by name desc; +----+-------+-------+ | id | name | score | +----+-------+-------+ | 5 | Zhou | 66.33 | | 7 | Zheng | 33.20 | | 1 | Zhao | 95.33 | | 6 | Wu | 99.32 | | 8 | Wang | 99.30 | | 3 | Sun | 44.55 | | 2 | Qian | 94.33 | | 4 | Li | 33.55 | +----+-------+-------+ 8 rows in set (0.00 sec)
#where条件查询 mysql
> select * from exam_score where name=Li; +----+------+-------+ | id | name | score | +----+------+-------+ | 4 | Li | 33.55 | +----+------+-------+ 1 row in set (0.00 sec) mysql> select * from exam_score where id=3; +----+------+-------+ | id | name | score | +----+------+-------+ | 3 | Sun | 44.55 | +----+------+-------+ 1 row in set (0.00 sec) mysql> select * from exam_score where name=Zhao and score<=99.0; +----+------+-------+ | id | name | score | +----+------+-------+ | 1 | Zhao | 95.33 | +----+------+-------+ 1 row in set (0.00 sec)

 

程序媛计划——mysql 插入、查找、修改、删除数据

标签:计划   sql   exist   not   cat   duplicate   字段   rds   rem   

原文地址:http://www.cnblogs.com/IcarusYu/p/7496771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!