找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
1、查找zhao这个人,他的分数
select(死勒得) scroe from(佛若) ddd where(味儿) name=‘zhao’;
2、查找wang这个人,他的分数
select(死勒得) age(诶几),scroe from(佛若) ddd where(味儿) name=‘wang’;
select age,scroe from ddd where name=‘wang’;
3、不显示其他信息not in
select(死勒得) * from ddd where age not in(20,21);
4、查询范围内的数据
select * from ddd where age between 19 and 23;     查询年龄19-23范围内的所有信息
5、查找为空的所有信息
select * from ddd where scroe is null;   查找分数为空的所有信息
6、查找不为空的所有信息
select *from ddd where scroe is not null;    查找分数不为空的所有信息is not null
7、查询模糊匹配:like(耐克)
select *from ddd where name like ‘zh%';    知道开头的模糊匹配
select *from ddd where name like ‘%ao';    知道结尾的模糊匹配
select *from ddd where name like ‘%a%';   知道中间的模糊匹配
8、截取某行或者某行到某行:limit(妮米特)
查找表中数据:6--10的数据:6-1=5    5+?=10      5    limit:5,5;   
                        8--25的数据:8-1=7     7+?=25     18   limit:7,18;
                   查看第7行数据:7-1=6     6+?=7      1       limit:6,1;
select *from ddd limit 1;查看第一行数据
select *from ddd limit 2,5;查看3-7行数据
9、排序:order by(哦得拜)
从大到小:降序:order by desc
select *from ddd order by scroe desc; 降序,大到小
从小到大:升序:order by asc
select *from ddd order by scroe asc; 升序,小到大
注意:order by 前面不能直接解where条件表达式
where order by scroe asc;错误不能这样
where name=‘zhangsan’ order by scroe asd;这样可以接
10、分组(去重)group by(葛入拜)
根据姓名分组:select *from dcs group by name;
select *from dcs group by class(克拉斯);  
having相当于where条件,where是不能直接使用聚合函数,having可以
如果某些情况用where无法使用,可以尝试使用having
一般having是结合group by 使用且是放在group by后面

数据库常问的面试题:
如何去重:
答:group by(葛入拜)  distinct 都等于去重
11、备份表结构 like(耐克)
create table dcs1 like dcs;只能备份表结构不能备份表数据
12、备份表数据
insert(英色) into(英吐) dcs1 select(死勒特) *from(佛弱) dcs;备份所有的表数据
insert(英色) into(英吐) dcs1(name,agee)select(死勒特) name,agee from(佛弱) dcs;备份表数据一部分
13、备份数据库:大于号>备份(此命令在liunx交互界面完成)
mysqldump -uroot -p123456 dcs>dcs.sql
14、还原数据库:小于号<还原(此命令在liunx交互界面完成)
mysql -uroot -p123456 xiaoqian
15、mysql中常用的聚合函数
1、统计: select count(*)(康特)select count(*)from 表名称;  统计表中总行数
                 select count(*)a from 表名称;    取别名
2、求最大 : max
select max(score)from 表名称;   查询最大的值         
3、求最小:min
select min(score)from 表名称;  查询最小的值
4、求和:sum(散)
select sum(age)from 表名称;  求分数之和
5、求平均:avg
select avg(score)from 表名称;求分数的平均值


分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册