1、select scroe from aaa where name='zhang';
在aaa中查找zhang这个人,告诉我他的分数
2、select scroe,age from aaa where name='wang';
在aaa中查找wang这个人,告诉我他的分数和年纪
3、select * from aaa where age not in (20,21);
代表不显示年级20,21的所有信息
4、select * from aaa where age between 19 and 25;
查询aaa表中年龄在19-25范围内的数据
5、select * from aaa where scroe is null;
查找分数为空的所有信息
select * from aaa where scroe is not null;
查找分数不为空的所有信息
6、select * from aaa where name like'zh%';
查找aaa中带zh的名字(%可放前中后使用 忘记哪里补哪里)
7、select * from aaa limit 1;
查找aaa中第一行数据
select * from aaa limit 2,5;
查找aaa中3到7行数据 ,前面是3-?=2 后面是2+?=7
select * from aaa limit 6,1;
查找aaa中第七行数据,前面7-1=6,6+?=7
8、select * from aaa order by score desc;
查aaa表中的成绩并从大到小排序;降序
select * from aaa order by score asc;
查aaa表中的成绩并从小到大排序;升序
9、select * from stu group by name;想到每个就想到group by(会取最上面的值)
select distinct(name)from aaa
10、create table aaa1 like aaa;
把aaa表结构备份一份,且新建一个新的aaa1
11、备份表的数据
insert into aaa1 select * from aaa;
把aaa表的所有数据进行备份到aaa1中
insert into aaa1(name,age)select name,age from aaa;
把aaa表中的某几个字段备份到aaa1中
11、备份数据库需回到linux >是备份 <是还原
mysqldump -uroot -p123456 dcs68>dcs68.sql
进入根目录的指定存放文件夹 把root用户中对应的dcs68这个数据库
备份到当前文件夹内并改名为dcs68.sql
mysqldump -uroot -p123456 xiaoqian<dcs68.sql;
进入存放已备份数据库的文件夹 把dcs68.sql还原到空数据库xiaoqian
12、mysql中常用的聚合函数(重点)count(*) max min sum vag
统计用count(*)
select count(*) from aaa;统计aaa中的数据有多少条
select count(*)a from aaa;把count(*)改别名为a
select count(*)as a from aaa;把count(*)改别名为a
最大用max (只能取最大值 无法取得其余信息)
select max(scroe)from aaa;查询aaa中最大的分数
最小用min
select min(scroe)from aaa;查询aaa中最小的分数
求和用sum
select sum(scroe)from aaa;求表中分数和总和
求平均用
select avg(scroe)from aaa;求表中分数平均
|