Oracle行转换列SQL语句

本文展示了一个复杂的SQL查询案例,通过多表联接、子查询及分组聚合操作,实现了按月统计不同阵营ID的计数。此查询涉及表连接、条件筛选、字段映射等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  select fmonth,sum(decode(factionid,1,fcount,0)) as factionid1,sum(decode(factionid,2,fcount,0)) as factionid2 from
  (
    select fmonth,factionid,count(*) as fcount from
    (
      select a.*,to_char(ftime,'yyyymm') as fmonth from sm_dzuserinfo_log a,
      (
      select fmobile,to_char(ftime,'yyyymm') as fmonth,max(ftime) as flasttime from sm_dzuserinfo_log
      group by fmobile,to_char(ftime,'yyyymm')
      ) b
      where a.fmobile = b.fmobile and to_char(a.ftime,'yyyymm')=b.fmonth and a.ftime=b.flasttime
    )
    group by factionid,fmonth
    order by fmonth,factionid
  )
  group by fmonth
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值