使用insert语句向表中插入三个员工的信息。
rename table user to employee;
insert into employee(id,username,birthday,entry_date,job,salary,resume) values(1,'aaa','1980-09-09','1980-09-09','bbb',90,'aaaaa');
select * from employee;
插入数据的细节1
insert into employee values(1,'aaa','1980-09-09','1980-09-09','bbb',90,'aaaaa');
插入数据的细节2
insert into employee values('1','aaa','1980-09-09','1980-09-09','bbb','90','aaaaa');
插入数据的细节3(插入中文)
要告诉mysql客户采用gb2312编码
show variables like 'chara%';
set character_set_client=gb2312;
insert into employee(id,username) values('3','张三');
要想查看时不乱码
show variables like 'chara%';
set character_set_results=gb2312;
select * from employee;
将所有员工薪水修改为5000元。
update employee set salary=5000;
将姓名为’bbb’的员工薪水修改为3000元。
update employee set salary=3000 where username='bbb';
将姓名为’bbb的员工薪水修改为4000元,job改为ccc。
update employee set salary=4000,job='ccc' where username='bbb';
将bbb的薪水在原有基础上增加1000元。
update employee set salary=salary+1000 where username='bbb';
更新要注意的问题
update employee set username='ccc',salary=9000,birthday='1980-09-09',.....................
update where id=1;
删除表中名称为’zs’的记录。
delete from employee where username='bbb';
删除表中所有记录。
delete from employee;
使用truncate删除表中记录。
truncate table employee;
查询表中所有学生的信息。
select * from student;
查询表中所有学生的姓名和对应的英语成绩。
select name,english from student;
过滤表中重复的英语数据。
select distinct english from student;
在所有学生总分上加10分特长分。
select name,(chinese+english+math)+10 from student;
统计每个学生的总分。
select name,(chinese+english+math) from student;
使用别名表示学生分数。
select name as 姓名,(chinese+english+math)+10 as 总分 from student;
select name 姓名,(chinese+english+math)+10 总分 from student;
查询姓名为wu的学生成绩
select * from student where name='王五';
查询英语成绩大于90分的同学
select * from student where english>'90';
查询总分大于200分的所有同学
select name from student where (chinese+english+math)>200;
查询英语分数在 80-90之间的同学。
select name from student where english>80 and english<90;
select name from student where english between 80 and 90; == select name from student where english>=80 and english<=90;
查询数学分数为89,90,91的同学。
select * from student where math in(89,90,91);
查询所有姓李的学生成绩。
select * from student where name like '李%';
select * from student where name like '李_';
查询数学分>80,语文分>80的同学。
select * from student where math>80 and chinese>80;
对数学成绩排序后输出。
select name,math from student order by math;
对总分排序后输出,然后再按从高到低的顺序输出
select name 姓名,(chinese+english+math) 总分 from student order by (chinese+english+math) desc;
select name 姓名,(chinese+english+math) 总分 from student order by 总分 desc;
对姓李的学生成绩排序输出
select * from student where name like '李%' order by (chinese+english+math) desc;
统计一个班级共有多少学生?
select count(name) from student;
select count(*) from student;
统计数学成绩大于90的学生有多少个?
select count(*) from student where math>80;
统计总分大于250的人数有多少?
select count(*) from student where (chinese+english+math)>250;
关于 count的函数的细节 (count只统有值的行)
统计一个班级数学总成绩?
select sum(math) from student;
统计一个班级语文、英语、数学各科的总成绩
select sum(chinese),sum(english),sum(math) from student;
统计一个班级语文、英语、数学的成绩总和
select sum(chinese+english+math) from student;
统计一个班级语文成绩平均分
select sum(chinese)/count(*) from student;
统计一个班级语文成绩平均分
select avg(chinese) from student;
求一个班级总分平均分
select avg(chinese+math+english) from student;
求班级最高分和最低分
select max(chinese+math+english),min(chinese+math+english) from student;
对订单表中商品归类后,显示每一类商品的总价
select product,sum(price) from orders group by product;
查询购买了几类商品,并且每类总价大于100的商品
select product from orders group by product having sum(price)>100;
rename table user to employee;
insert into employee(id,username,birthday,entry_date,job,salary,resume) values(1,'aaa','1980-09-09','1980-09-09','bbb',90,'aaaaa');
select * from employee;
插入数据的细节1
insert into employee values(1,'aaa','1980-09-09','1980-09-09','bbb',90,'aaaaa');
插入数据的细节2
insert into employee values('1','aaa','1980-09-09','1980-09-09','bbb','90','aaaaa');
插入数据的细节3(插入中文)
要告诉mysql客户采用gb2312编码
show variables like 'chara%';
set character_set_client=gb2312;
insert into employee(id,username) values('3','张三');
要想查看时不乱码
show variables like 'chara%';
set character_set_results=gb2312;
select * from employee;
将所有员工薪水修改为5000元。
update employee set salary=5000;
将姓名为’bbb’的员工薪水修改为3000元。
update employee set salary=3000 where username='bbb';
将姓名为’bbb的员工薪水修改为4000元,job改为ccc。
update employee set salary=4000,job='ccc' where username='bbb';
将bbb的薪水在原有基础上增加1000元。
update employee set salary=salary+1000 where username='bbb';
更新要注意的问题
update employee set username='ccc',salary=9000,birthday='1980-09-09',.....................
update where id=1;
删除表中名称为’zs’的记录。
delete from employee where username='bbb';
删除表中所有记录。
delete from employee;
使用truncate删除表中记录。
truncate table employee;
查询表中所有学生的信息。
select * from student;
查询表中所有学生的姓名和对应的英语成绩。
select name,english from student;
过滤表中重复的英语数据。
select distinct english from student;
在所有学生总分上加10分特长分。
select name,(chinese+english+math)+10 from student;
统计每个学生的总分。
select name,(chinese+english+math) from student;
使用别名表示学生分数。
select name as 姓名,(chinese+english+math)+10 as 总分 from student;
select name 姓名,(chinese+english+math)+10 总分 from student;
查询姓名为wu的学生成绩
select * from student where name='王五';
查询英语成绩大于90分的同学
select * from student where english>'90';
查询总分大于200分的所有同学
select name from student where (chinese+english+math)>200;
查询英语分数在 80-90之间的同学。
select name from student where english>80 and english<90;
select name from student where english between 80 and 90; == select name from student where english>=80 and english<=90;
查询数学分数为89,90,91的同学。
select * from student where math in(89,90,91);
查询所有姓李的学生成绩。
select * from student where name like '李%';
select * from student where name like '李_';
查询数学分>80,语文分>80的同学。
select * from student where math>80 and chinese>80;
对数学成绩排序后输出。
select name,math from student order by math;
对总分排序后输出,然后再按从高到低的顺序输出
select name 姓名,(chinese+english+math) 总分 from student order by (chinese+english+math) desc;
select name 姓名,(chinese+english+math) 总分 from student order by 总分 desc;
对姓李的学生成绩排序输出
select * from student where name like '李%' order by (chinese+english+math) desc;
统计一个班级共有多少学生?
select count(name) from student;
select count(*) from student;
统计数学成绩大于90的学生有多少个?
select count(*) from student where math>80;
统计总分大于250的人数有多少?
select count(*) from student where (chinese+english+math)>250;
关于 count的函数的细节 (count只统有值的行)
统计一个班级数学总成绩?
select sum(math) from student;
统计一个班级语文、英语、数学各科的总成绩
select sum(chinese),sum(english),sum(math) from student;
统计一个班级语文、英语、数学的成绩总和
select sum(chinese+english+math) from student;
统计一个班级语文成绩平均分
select sum(chinese)/count(*) from student;
统计一个班级语文成绩平均分
select avg(chinese) from student;
求一个班级总分平均分
select avg(chinese+math+english) from student;
求班级最高分和最低分
select max(chinese+math+english),min(chinese+math+english) from student;
对订单表中商品归类后,显示每一类商品的总价
select product,sum(price) from orders group by product;
查询购买了几类商品,并且每类总价大于100的商品
select product from orders group by product having sum(price)>100;