请登录[¤ 阳光论坛 ¤]参与讨论


阳光宝宝
90

 □ 主题: mysql 多用途查询
 □ 内容: 1楼

      在使用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字段可以再处理,比如各分组占百分比等等 
      
——
      
争分夺秒背单词 → marriage  n.结婚,婚姻;婚礼
 □ 发帖时间:2011-12-30|10:19:52 |回复|返回|

 页次:1/1页 每页10  本主题贴数0 分页: 1


你还没有登录论坛,所以不能发表你的意见。你可以选择:

1、我已注册,我要

2、我还没注册,我要

3、太麻烦了,我还是

Go Top

Copyright by(C)2003-2015 http://abc.sy578.cn