占比

image.png怎么算这两个的占比,男的占比,女的占比sql,性别和个数列不去掉

FineReport 在菜鸟的菜鸡 发布于 2024-4-3 16:45 (编辑于 2024-4-3 17:38)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
华莉星宸Lv6高级互助
发布于2024-4-3 16:57

参考!

with aa as

 (select '男' as xb, 333 as rs

    from dual

  union all

  select '女' as xb, 555 as rs

    from dual)

    

select xb, rs, rs / zrs

  from (select * from aa, (select sum(rs) as zrs from aa))

image.png

最佳回答
0
用户k6280494Lv6资深互助
发布于2024-4-3 16:47(编辑于 2024-4-3 16:55)

image.png

select case when sex='男' then gs/(select sum(sl) from a)

                  else   gs/(select sum(sl) from a) end zb from a

最佳回答
0
snrtuemcLv8专家互助
发布于2024-4-3 16:54

select case when 性别='男' then 个数/sum(个数) end 男占比,case when 性别='女' then 个数/sum(个数) end 女占比 from 表

  • 4关注人数
  • 158浏览人数
  • 最后回答于:2024-4-3 17:38
    请选择关闭问题的原因
    确定 取消
    返回顶部