woshidute 2017-10-13 02:51 采纳率: 0%
浏览 1314
已结题

遇到了不会写的sql,没有思路

图片说明

  • 写回答

5条回答 默认 最新

  • Amo_lt 2017-10-13 04:03
    关注
     select max(year) as '年份',
           (select count(*) from 表 b where b.sex='男' and b.company='c1' and a.year=b.year) as 'c1男' ,
           (select count(*) from 表 c where c.sex='女' and c.company='c1' and a.year=c.year) as 'c1女' ,
           (select count(*) from 表 d where d.sex='男' and d.company='c2' and a.year=d.year) as 'c2男' ,
           (select count(*) from 表 e where e.sex='女' and e.company='c2' and a.year=e.year) as 'c2女' ,
           (select count(*) from 表 f where a.year=f.year) as '合计'
    
    from 表 a group by a.year union all
    select '合计', 
           (select count(*) from 表  where sex='男' and company='c1') as 'c1男' ,
           (select count(*) from 表  where sex='女' and company='c1') as 'c1女' ,
           (select count(*) from 表  where sex='男' and company='c2') as 'c2男' ,
           (select count(*) from 表  where sex='女' and company='c2') as 'c2女' ,
           (select count(*) from 表  ) as '合计'
     from 表 group by '合计'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器