Mysql教程:(六)修改語句、、刪除語句、字符查詢like


1、修改語句

update 表名 set  where 條件

mysql> update student set birth=1988,department='中文系' where id=901 and name='張老大';

把張老大的出生日期修改為1988,院系修改成中文系

mysql> update student set birth=birth-5;

2、刪除語句

刪除901同學的,學生信息

mysql> delete from student where id=901;

刪除湖南籍學生的信息

mysql> delete from student where address like "湖南%";

清空學生表信息

mysql> delete from student;

3、字符查詢like

查詢地址為北京的學生信息

mysql> select * from student where address like '北京%';

查詢地址為北京市昌平區的學生信息

mysql> select * from student where address like '%北京%平%';

查詢湖南籍學生的成績信息;

mysql> select * from score where stu_id in (select id from student where address like '湖南%');

4、作業

1,把張三的計算機成績修改成60分

update score set grade=60 where stu_id in(select id from student where name='張三')and c_name='計算機';

2,把計算機科目的分數降低5分

update score set grade=grade-5 where c_name='計算機';

3,把湖南省學生計算機分數提高5分

 update score set grade=grade+5 where c_name='計算機'and stu_id in(select id from student where address like '湖南%');

4,把學號為904的學生,計算機成績改為85

 update score set grade=85 where c_name='計算機' and stu_id=904;

5,刪除904學生的成績

delete from score where stu_id=904;

6,刪除湖南籍貫學生的成績

 delete from score where stu_id in(select id from student where address like '湖南%'); 

7,刪除王姓與張姓同學英語成績

delete from score where stu_id in (select id from student where name like '王%'or name like '張%') and c_name='英語';

8,刪除年紀大於30的學生的計算機成績

 delete from score where stu_id in (select id from student where 2016-birth>30);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM