-- 1、全查
select * from hzuser;
-- 2、条件查询
-- 等于
select * from hzuser where hzUserNum = 5484;
-- 不等于
select * from hzuser where hzUserNum != 5484;
select * from hzuser where hzUserNum <> 5484;
-- 大于
select * from hzuser where userSal > 3000;
-- BETWEEN...and... 相当于 >= <= 一个区间值
select * from hzuser where userSal BETWEEN 3000 and 5000;
-- is : comm 是 null
select * from hzuser where comm is null;
-- is not: comm 不是 null
select * from hzuser where comm is not null;
-- and :且 job='备胎' 且 usersal > 1300;
select * from hzuser where job='备胎' and usersal > 1300;
-- or in:或 job='备胎' 或 job='太监';
select * from hzuser where job='备胎' or job='太监';
select * from hzuser where job in('备胎' , '太监');
-- 模糊查询:like:通配符:_、%
-- 排序:order by asc(升)/desc(降)
-- 函数:count求总条数,sum求和,avg平均数,round四舍五入 Max最大值、Min最小值
-- Where过滤:分组之前过滤:对数据源进行过滤。
-- Having过滤:分组之后的过滤
-- Limit:限制查询结果的条目数
-- DISTINCT:去重
-- 练习:查询 工资大于1000 并且 职业太监 多少条
select * from hzuser where userSal>1000 and job="太监";
-- avg 平均值
select DISTINCT 3832.00/19 from hzuser; -- 201 19个人的平均值
SELECT avg(comm) from hzuser; -- 425 和上面的数据不对等
SELECT avg(ifnull(comm,0)) from hzuser; -- 和上面就对等了
-- max 、min 最大值,最小值
-- 工资最高的是多少
select max(userSal) from hzuser;
-- 求出 工资最高的人的名字和最高的工资数字
select * from hzuser where userSal=(select max(userSal) from hzuser);
-- 分页
索引= (页数-1)*条数 分页公式
8891

被折叠的 条评论
为什么被折叠?



