SELECT 产品,
Count(订单编号) AS 订单总数,
Sum(订购金额) AS 订购金额总额,
Avg(订购金额) AS 平均订单金额
FROM 订购明细
GROUP BY 产品;
SELECT IF(年龄<=20,"20岁及其以下",
IF(年龄<=30,"21-30岁",
IF(年龄<=40,"31-40岁","40岁以上")
)
) AS 年龄分组,
Count(用户ID) AS 用户数
FROM 用户明细
GROUP BY IF(年龄<=20,"20岁及其以下",
IF(年龄<=30,"21-30岁",
IF(年龄<=40,"31-40岁","40岁以上")
)
);
select 年龄分组, count(*) from (
SELECT IF(年龄<=20,"20岁及其以下",
IF(年龄<=30,"21-30岁",
IF(年龄<=40,"31-40岁","40岁以上")
)
) AS 年龄分组 FROM 用户明细
) t GROUP BY 年龄分组;
SELECT DATE_FORMAT(注册日期, '%Y年%m月') AS 年月,
Count(用户ID) AS 用户数
FROM 用户明细
GROUP BY DATE_FORMAT(注册日期, '%Y年%m月')
HAVING 用户数<1000;
网友评论