java-zh 2021-03-24 18:05 采纳率: 77.8%
浏览 138
已采纳

union all 查询多个 count

select * from (
select count(1) from pf_company_info where delete_flag = 0 and cate_one = 2 and cate_two like '%201%'
UNION ALL
select count(1) from pf_company_info where delete_flag = 0 and cate_one = 1 and cate_two like '%102%'
UNION ALL
select count(1) from pf_company_info where delete_flag = 0 and cate_one = 3 and cate_two like '%301%'
)a

现在的结果是

count

89

0

0

我想变成

count1 count2 count

89           0          0

请求大佬帮忙!

 

  • 写回答

2条回答 默认 最新

  • 沐川 2021-03-24 18:45
    关注

    如下:

    select (
    select count(1) from pf_company_info where delete_flag = 0 and cate_one = 2 and cate_two like '%201%'
    ) as count1,(
    select count(1) from pf_company_info where delete_flag = 0 and cate_one = 1 and cate_two like '%102%'
    ) as count2,(
    select count(1) from pf_company_info where delete_flag = 0 and cate_one = 3 and cate_two like '%301%'
    ) as count3
    from dual;
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?