找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
本帖最后由 dcs68陈跃聪 于 2021-11-22 20:10 编辑

1、select scroe from stu where name='chen';
查询陈这个人的分数是多少
2、select age,scroe from stu where name='chen';
查询陈这个人的分数和年纪是多少
3、select * from stu where age not in(20,21);  not in 表示不等于某个值
显示年龄不是20,21的所有信息
4、select * from stu where age between 23 and 30;
查询年纪时23到30的所有信息(包含23和30)
5、select * from stu where name is not null;
查询名字非空的所有信息
6、select * from stu where name is null;
查询名字为空的所有信息
7、like 模糊匹配开头,中间,结尾
select * from stu where name like'%en'
select * from stu where name like'c%n'
select * from stu where name like'ch%'
8、limit    截取某行,或者某行到某行
select * from stu limit 1;  查询第一行的所有信息
select * from stu limit 4; 查询前四行的所有信息
select * from stu limit 6,1; 查询第七行的信息
select * from stu limit 2,5; 查询三到七行的信息
9、排序 :order by 字结构 asc 升序   order by 字结构 desc  降序
select * from stu order by scroe asc; 分数从小到大 升序
select * from stu order by scroe desc 分数从大到小 降序
注意:order by 前面不能直接加where,需在where 后面加内容才行
10、分组、去重 group by  去重  distinct
select * from stu group by class;
根据班级进行分组,如果班级有重复,只会显示前面的。
11、create table w1 like w;
把w的表结构备份,并且创建一个叫w1的表。 只备份结构不备份数据
12、insert into w1 select * from w;
把w表中的所有数据备份到w1  注意: w 和 w1 的表结构要一致13、mysqldump -uroot -p123456 dcs68>beifeng;
把dcs68的数据备份一份,名称为beifeng
14、mysql -uroot -p123456 tt<beifeng;
把beifengl这个文件中的所有表还原到tt这个数据库中
15、select count(*)from stu;  统计表中总行数
select count(*)a from stu;取别名select count(*)as a from stu;取别名
16、select max(bb) from stu;求bb的最大值
注意:分数最大的值肯定是OK,但是如果你取其它值,非第一行,其它都是
错误的。

17、求最小 min
select min(score)from stu;求分数最小的
注意:分数最小的值肯定是OK,但是如果你取其它值,非第一行,其它都是
错误的。
18、求和 sum
select sum(score) from stu;求分数之和
19、求平均 avg
select avg(scroe)from stu;求分数平均值





分享至 : QQ空间
收藏

0 个回复

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