在使用mysql查询时既要查询分组的合计数,又要查询全部查询结果合计数,即使用group by语句时,sql可以这样写: select sum(amount) as total_amount,trans_pro,total from trans_2011 a ,(select sum(amount) as total from trans_2011 where fromwhere=''33000111'') b where fromwhere=''33000111'' group by trans_pro, a 和 b必须写,为别名,否则会出错。输出结果如下: total_amount trans_pro total 4760901.68 1 5897861.28 1136959.60 2 5897861.28 total字段可以再处理,比如各分组占百分比等等
|