成都10班蔡阳 发表于 2021-11-22 18:45:08

MySQL(2)

1、select name from student;从student中选出字段name下所有类容
2、select name,class from student ;同时在student中查询2个字段
3、select * from student where class=1833;查询所有班级位1833 所有的学生信息。
4、select * from student where class=1833 or class=1834;查询班级位1833或者按班级为1834所有学生的信息,不能用and链接,只能用or
5、select * from student where class!=1833;表示不等于!=和<>表示
6、select * from student where name=‘zhangsan’ and class=1833;and两边可以接两个不同的字段等于具体值
7、select * from student where age between25 and 31;查询年龄在25岁到31岁之间所有学生的信息。
8、select * from student where age >= 25 and age<=31;查询年龄在25岁到31岁之间所有学生的信息。和between.......and.......同理。
9、select * from student where class in(1833,1834);将在班级1833和1834班级所有学生的信息查找出来,否定用not in
10、select * from student where class is null;当为空值时不能用=,要用is,查询不为空用is not
11、select * from student where name like "xiao%";like表示模糊查询,%代替未知的字符,可以放在前中后。
12、select * from student whereid limit5;表示查找字段id前5行的数据;
      select * from student whereid limit1,4;表示查询2-5行的数据,m是下标,n是行数,数据库表格中第一行数据记录为0;
13、聚合函数:
      selectcount(*) from+表名;统计表名的行数    注:count后面尽量不要接字段名,如果要单独统计某个字段,也是可以接单个字段名的。
       selectsum(字段名) from +表名:表示将某一个字段求和;
       selectavg(字段名) from +表名:表示将某一个字段求平均数;
       selectmax(字段名) from +表名:表示将某一个字段求最大值;
       selectmin(字段名) from +表名:表示将某一个字段求最小值;
       selectdistinct(字段名) from +表名:表示将某一个字段去重;
       select * form +表名 order by+字段名asc :表示将一个字段名升序排列;
       select * form +表名 order by+字段名desc :表示将一个字段名降序排列;
14、降取出得字段以别名方式显示,可以在原字段后面接as+别名,或者用原字段+空格+别名;
15、deletefrom +表名   where+字段名:从表中删除某个字段
16、deletefrom +表名   where+字段名+ in:删除多条数据
17、tuuncate+表名:表示删除表中的数据,不删除表,
17、drop table+表名:表示删除整张表,同时将表数据和表结构一起删除
18:update+表名 set字段名+where条件;更新表里的数据





















页: [1]
查看完整版本: MySQL(2)