SQL先合计一列的总数再分组统计

有一张表,如下图所示:

先合计了bwet一列的总数=11.83,再分组统计每个货号的bwet重量,再求得一列为每个货号的bwet重量/11.83:
item_code bwet sum(bwet)/11.83
FK11 0.5 0.04
Fk22 3.2 2.7
……
应该如何写SQL语句?
可能描述的有点问题,整个意思就是:
从kt_al表里查询2012-8-1日Bwet,以货号汇总,要求显示:
货号 | bwet | bwet/8-1日所有的bwet和

先把你这个查询语句用括号括起来
下面就这样了
select a.item_code,sum(a.bwet), sum(a.bwet)/11.83 from
(select item_code,bwet from kt_al where packdate>='2012-8-1' and packdate<'2012-8-2') a
group by a.item追问

大哥,有点你可能误解了,11.83就是这个所有行的总数和,而并不是单单指出的常量

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-16
ORACLE:
select item,bwet,s.totalBwet/bwet from tableGroup g,
(select sum(bwet)totalBwet from tableSum) s
第2个回答  2012-08-16
select item_code,sum(bwet)/11.83 from
from kt_al where packdate>='2012-8-1' and packdate<'2012-8-2'
group by item
union all
select '',sum(bwet),0 from
from kt_al where packdate>='2012-8-1' and packdate<'2012-8-2'追问

大哥,有点你可能误解了,11.83就是这个所有行的总数和,而并不是单单指出的常量

追答

select a.item_code,a.bwet,a.bwet/b.sbwet
(select item_code,sum(bwet)as bwet from
from kt_al where packdate>='2012-8-1' and packdate='2012-8-1' and
packdate<'2012-8-2')b

本回答被提问者采纳
相似回答