时间:2021-07-01 10:21:17 帮助过:23人阅读
查询小乔的年龄:select age from students where name=‘小乔‘ 查询20岁以下的学生:select * from students where age<20 查询家乡不在北京的学生:select * from students where hometown<>‘北京‘
查询年龄小于20的女同学:select * from students where age<20 and sex=‘女‘ 查询女学生或‘1班‘的学生:select * from students where sex=‘女‘ or class=‘1班‘ 查询非天津的学生:select * from students where not hometown=‘天津‘
查询姓孙的学生:select * from students where name like ‘孙%‘ 查询姓孙且名字是一个字的学生:select * from students where name like ‘孙_‘ 查询叫乔的学生:select * from students where name like ‘%乔‘ 查询姓名含白的学生:select * from students where name like ‘%白%‘
查询家乡是北京或上海或广东的学生:
select * from students where hometown in (‘北京‘,‘上海‘,‘广东‘) select * from students where hometown not in (‘北京‘,‘上海‘,‘广东‘)
查询年龄为18至20的学生 between 18 and 20,小值在前:
select * from students where age between 18 and 20
查询学生的年龄和班级,消除相同的数据
select distinct age,class from students
查询学生的所有信息,一个学生只记录一次 select distinct * from students
查询没有填写身份证的学生:
select * from students where card is null
判断身份证为空字符
select * from students where card is not null select * from students where card=‘‘
查询所有学生信息,按年龄从小到大排序:asc:升序(默认升序)
select * from students order by age asc
查询所有学生信息,按年龄从大到小排序:desc:降序
select * from students order by age desc
查询所有学生信息,按年龄从大到小排序,年龄相同时,再按学号从小到大排序:
select * from students order by age desc,studentNo
count,min,max,sum,avg
查询学生总数:count(card) 不统计为null数据 select count(*) as 学生总数 from students select count(name) from students select count(card) from students 查询女生的最小年龄:select min(age) from students where sex=‘女‘ 查询1班的最大年龄:select max(age) from students where class=‘1班‘ 查询北京学生的年龄总和:select sum(age) from students 查询女生的平均年龄:select avg(age) from students where sex=‘女‘
查询各种性别的人数:select sex,count(*) from students group by sex 查询各种年龄的人数:select age,count(*) from students group by age 查询男生总人数:having后面的条件运算符与where的相同 select sex,count(*) from students group by sex having sex=‘男‘ select count(*) from students where sex=‘男‘
从start开始,获取count条数据,start索引从0开始:select * from 表名 limit start,count
每页显示m条数据,求:显示第n页的数据
select * from students limit (n-1)*m,m
求总页数:
查询总条数p1
使用p1除以m得到p2
如果整除则p2为总数页
如果不整除则p2+1为总页数
注意:
int(1) 长度没有意思
varchar(5) 5个字符
decimal(5,2) 3个整数,2个小数,添加数据超过长度,自动四舍五入
datetime
命令行客户端,使用,查看某一个数据类型的使用帮助
help tinyint
007-数据库之“查”
标签:tin having 数据 北京 表名 color 模糊 最小 统计