这个是字段下的值
然后写一条情况让他这样显示出来
就是怎么写一条sql语句查询一个字段下某个值的占比情况
这个是字段下的值
就是怎么写一条sql语句查询一个字段下某个值的占比情况
可以先sql查询出各阶段汇总数据,然后程序中将各个汇总数据和总数据相除,计算出百分比返回给前端,如果对你有所帮助的话,希望能够被采纳
SELECT
COUNT(
CASE
WHEN member_count <= 30
THEN 1
END
) AS count_1,
COUNT(
CASE
WHEN member_count > 30
AND member_count <= 40
THEN 1
END
) AS count_2,
COUNT(
CASE
WHEN member_count > 40
AND member_count <= 50
THEN 1
END
) AS count_3,
COUNT(
CASE
WHEN member_count > 50
AND member_count <= 60
THEN 1
END
) AS count_4,
COUNT(
CASE
WHEN member_count > 60
AND member_count <= 70
THEN 1
END
) AS count_5,
COUNT(
CASE
WHEN member_count > 70
AND member_count <= 80
THEN 1
END
) AS count_6,
COUNT(
CASE
WHEN member_count > 80
AND member_count <= 90
THEN 1
END
) AS count_7,
COUNT(
CASE
WHEN member_count > 90
AND member_count <= 100
THEN 1
END
) AS count_8
FROM xxx;