1、Switch函数
SELECT 用户ID,
SWITCH(年龄<=20,"20岁及其以下",
年龄<=50,"50岁以下)
AS 年龄分组
FROM chart1;
2、Formate函数
FORMATE(时间,时间格式参数);
summary
给数据库中的数据做筛选的时候,数据用switch较好,日期用format较好;
3、数据去重
- GROUP BY
- DISTINCT
4、简单统计
SELECT
Count(订单编号) AS 订单总数,
Sum(订单金额) AS 订购金额总额,
FROM 订购明细;
5、分组统计
GROUP BY
SELECT 产品,
Count(订单编号) AS 订单总数
FROM 订购明细
GROUP BY 产品;按时间提取数据
SELECT FORMAT(订购日期,“h”) AS 时段,
FROM 订购明细
GROUP BY FORMAT (订购日期,"h");