Sql语法
-- 选择排序 先执行from,再执行where,再执行select
-- 1.等值比较 = !=
select * from t_shop where s_price = 4
-- 2.关系比较< >
select * from t_shop where s_price > 2
-- 3.逻辑关系 and or
select * from t_shop where s_price > 2 and s_name like '_瓜'
select * from t_shop where s_price > 2 or s_name like '_瓜'
-- 4.范围比较 between and (时间范围)
select * from t_shop where s_price BETWEEN 1 and 5
select * from `机架式服务器` where `邮寄日期` between '2018-04-12' and NOW()
-- 5.集合比较 in not in
select * from t_shop where s_price in(2,4,6)
select * from t_shop where s_price not in(2,4,6)
-- 6.模糊查询 like (%任意字符) (_单字符)
select * from t_shop where s_name like '_瓜'
-- 7.空值比较is null 查询为空的 in not null 查询不为空的
select * from `机架式服务器` where f24 is null
select * from `机架式服务器` where f24 is not null
--8.排序操作 desc降序 asc升序
select * from t_shop ORDER BY s_id desc
select * from t_shop ORDER BY s_id asc
select * from t_shop ORDER BY s_price asc,s_id desc
-- 聚合函数进项数据处理
-- count 统计
-- *统计所有行,包括null值
SELECT count(*) '数据量' FROM `机架式服务器`
-- all列 统计指定的所有非空值行
select count(all `序号`) '数据量' from `机架式服务器`
-- distinct 统计指定列的所有唯一非空值行 (去重)
select count(distinct `邮寄人`) '数据量' from `机架式服务器`
-- sum求和
-- 统计总和 all可省略
select SUM(`数量`) '数量和' from `机架式服务器`
-- distinct 求和非null 并且去重
select SUM(DISTINCT `数量`) '数量和' from `机架式服务器`
-- avg 求平均 avg自身不统计null进行计算 可用ifnull
select avg(`数量`) '平均数'from `机架式服务器`
-- ifnull
select avg(ifnull(`数量`,0)) '平均数'from `机架式服务器`
-- 方法2 sum / 数量
SELECT sum(`数量`) / count(DISTINCT `邮寄人`) '平均数' from `机架式服务器`
-- 求最大最小 max min
-- max 最大
select max(`数量`)'最大' FROM `机架式服务器`-- 不统计null
-- min 最小
select min(`数量`)'最小' FROM `机架式服务器`-- 不统计null