oracle sql合计结果信息使用分组的小问题
--月统计 Select SUBSTR(t.BalanceDate,1,6) as Mon, t.RechargeType , SUM(t.SumNum) as SumNum , SUM(t.SumFee) as SumFee From Recharge t Where to_char(to_date(t.BalanceDate,'yyyy-mm-dd'),'yyyymm') BETWEEN to_char(to_date('2016-07-01','yyyy-mm-dd'),'yyyymm') AND to_char(to_date('2016-07-01','yyyy-mm-dd'),'yyyymm') and t.rechargetype='1' Group by SUBSTR(t.BalanceDate,1,6) , t.RechargeType Order by SUBSTR(t.BalanceDate,1,6) DESC
--年统计 Select SUBSTR(t.BalanceDate,1,4) as Year, t.RechargeType , SUM(t.SumNum) as SumNum , SUM(t.SumFee) as SumFee From Recharge t Where to_char(to_date(t.BalanceDate,'yyyy-mm-dd'),'yyyy') BETWEEN to_char(to_date('2016-07-01','yyyy-mm-dd'),'yyyy') AND to_char(to_date('2016-07-01','yyyy-mm-dd'),'yyyymm') and t.rechargetype='1' Group by SUBSTR(t.BalanceDate,1,4) , t.RechargeType Order by SUBSTR(t.BalanceDate,1,4) DESC
根据年月统计分组 请注意group by 和order by 排序字段 要和查询条件的取值一样。点点滴滴随记一笔。