找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
15.不显示年纪是20,21岁的所有信息
select * from 表名 where age not in(20,21);
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\0935eb1c152f475386c67945118fd208\])r6tv6~55~t)b}wzgq7r8m.png

16.查询年纪19-23范围内的所有信息
select * from 表名 where age between 19 and 23;
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\0672448c4f6348bb90fd459fcdf2d1af\t%1)unx{onf]0evpy$]ua2a.png
17,查找分数为空的所有信息is null
select * from 表名 where sorce is null;
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\1f6cf31f56da410da2bfd38594551cbc\$xs_ip`0h768a_6ve48dt0f.png
18.查找分数不为空的所有信息is not null
select * from 表名 where sorce is not null;
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\aba6f7cb95814676a3efbe950418912a\q`)rcbx6qbmxhqowifny]ic.png
19.like 模糊匹配开头,结尾,中间
开头:select * from 表名 where name like 'a%';
中间:select * from 表名 where name like'%a%';
结尾;select * from 表名 where name like'%a';
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\af8cd63bd33b4e199448c8ea7f8cd080\p925zx@u~$y~8mc6tlema{a.png
20.截取某行或者某行到某行limit
查找表中的数据:3-10的数据  3-1=2   2+?=10 8
          limit 2,8;
查找表中的数据:8-25的数据  8-1=7   7+?=25 18
          limit 7,18;
查找表中的数据:第7行的数据 7-1=6    6+?=7
          limit 6,1;
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\89ea29fe6ac14a59a8042688f6566bbf\468_5%u[xzm$9~$%ba}r~@1.png[/img]
21.排序
从大到小:降序 order by  desc
select * from 表名 order by 字段 desc;
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\fb32b3bd039644af8a7118dd746e00eb\[j$f})n_8b$itbv0rjkg(@d.png[/img]
从小到大:升序 order by  asc
select * from 表名 order by 字段 asc;
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\68e9a8a6b2074b6a81b48936ce2c1fec\sdaq0jgpwb@~@8d$or`sk{t.png
注意:order by 前面不能直接接where 条件表达式
where order by scroe asc;错误不能这样接
where name='zhangsan' order by scroe asd;这样可以接

22、分组(去重)
根据姓名分组:select * from 表名 group by name;
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\b921301ed418450e8d0301b863958d8d\7%y7$([}rlpc9`)@lx%d5`x.png[/img]
having相当于where条件,where是不能直接使用聚合函数,having可以
如果某些情况用where无法使用,可以尝试使用having
一般having是结合group by 使用且是放在group by后面
数据库常问的面试题:
如果去重?
答:distinct去重  group by 去重
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\82a8bdc059b544bc82141de79a26f291\q1p62}df9ow9ip@~n@h9nzy.png[/img]
23.备份表结构 like
create table stu1 like stu;
把stu表结构备份一份,且新创建一个新的表stu1(只备份结构不备份数据)
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\993b91714c654ea39837a3bba5a26000\v(q9{cl~aln8m0ugw]t(tfj.png
24.备份表的数据
insert into stu1 select * from stu;
把stu表的所有数据进行备份到stu1中
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\db4e594932264438a5a69d4e41e68408\c11q{v_qdjkzziqfj`$am3m.png
把stu表中的某几个字段备份到stu1中
insert into stu1(name,age)select name,age from stu;
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\020c3cd470a246d4a3a4b5738c9d7c2b\jqm`rded9i5]1(sz(0igy0h.png
25.备份数据库 >
mysqldump -uroot -p123456 dcs68>dcs.sql
把root用户中对应的dcs68这个数据库备份一份,名称是dcs68.sql
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\695354e057504dfd8bf32827a948b518\5{k27a4a702~36[5jaoi637.png[/img]
此命令操作是在:liunx交互界面完成

26.还原数据库 <
mysql -uroot -p123456 xiaoqian<dcs68.sql
把dcs68.sql这个文件中的所有表还原到xiaoqian这个数据库中
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\cc1642b763fe43109902fe1915ced65e\e)]3`$}r1[x[`({hach7`j5.png[/img]
27.MySQL中常用的聚合函数(重点)
1、统计 count(*)
select count(*)from stu; #统计表中总行数
select count(*)a from stu;取别名
select count(*)as a from stu;取别名
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\8473db79c2b144faa6c97e3d66c5de41\[7`bn56}dsb7~j$fc$iy`s9.png[/img]
2、求最大 max
select max(score)from stu;求分数最大的
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\3abc5cb42c5749faa86ff56ea960f8f4\~zw[zelk$83x76h77i(}nkq.png[/img]
注意:分数最大的值肯定是OK,但是如果你取其它值,非第一行,其它都是
错误的。
3、求最小 min
select min(score)from stu;求分数最小的
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\30f1d1cad2ef4b6ea6749e20af7af892\))[h]fvbw8u0t5(ll1$y%w4.png[/img]
注意:分数最小的值肯定是OK,但是如果你取其它值,非第一行,其它都是
错误的。
4、求和 sum
select sum(score) from stu;求分数之和
[img=620,0]C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\a7f2db2c7e4b4f6d97b3bd0a0b18c441\h@vdzc_r[v[10qn@h0o5mk6.png[/img]
5、求平均 avg
select avg(scroe)from stu;求分数平均值
C:\Users\Administrator\AppData\Local\YNote\data\qqD133DE656A50BF083958736185202812\f4e4edb5c1ff4f838706f080cb96c510\9~zkto)wz0del}s`cs}_2`r.png

分享至 : QQ空间
收藏

0 个回复

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