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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序