我有图一这个结果集,想做出第二种结果集,怎么写啊

SELECT    

        neck AS 颈围,

        customer_neck AS 客户颈围, 

        JWPC  AS 颈围偏差,

        chest AS 胸围, 

        customer_chest AS 客户胸围,

        XWPC  AS  胸围偏差

FROM

        customer_measure

FineReport 十万个小问题 发布于 2022-7-4 14:03
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共4回答
最佳回答
1
CD20160914Lv8专家互助
发布于2022-7-4 14:04(编辑于 2022-7-4 14:10)

你是要统计个数。还是?直接case when 再结合count

select 

tmp.type_name,

sum(case when tmp.偏差='偏小' then 1 else 0 end ) as 偏小,

sum(case when tmp.偏差='偏大' then 1 else 0 end ) as 偏大,

sum(case when tmp.偏差='正常' then 1 else 0 end ) as 正常

from (

SELECT    

     '颈围' as type_name,

        --customer_neck AS 客户颈围, 

        JWPC  AS 偏差      

FROM

        customer_measure

        union all

select 

        '胸围' as type_name,

        --customer_chest AS 客户胸围,

        XWPC  AS  偏差

        from customer_measure

        ) tmp

最佳回答
0
snrtuemcLv8专家互助
发布于2022-7-4 14:11

这个报表可以处理,你把你的数据导出成为内置数据集,给你修改把

最佳回答
0
yzm339714Lv6中级互助
发布于2022-7-4 14:11

https://bbs.fanruan.com/wenda/question/123665.html

 这个不是之前回答过你了嘛,然后报表设计的时候, type 做纵向扩展,偏差 做横向扩展,就可以了啊

最佳回答
0
jenniferjunLv4初级互助
发布于2022-7-4 14:16

建议使用case when 和 sum函数  sum(case when JWPC='偏大' then 1 else 0) as 颈围偏大, sum(case when JWPC='偏小' then 1 else 0)  as 颈围偏小 其他的一样这样写

  • 5关注人数
  • 280浏览人数
  • 最后回答于:2022-7-4 14:16
    请选择关闭问题的原因
    确定 取消
    返回顶部