create table t(AA varchar(10),CC varchar(10),DD int)
insert t
select '0002','USER0',12
union all
select '5260','USER2',10
union all
select '5260','USER2',10
union all
select '0002','USER1',12
union all
select '0002','USER1',12
union all
select '5260','USER3',10
union all
select '5260','USER4',10
union all
select '5260','USER4',10 select a.aa,a.cc,a.dd,(select dd/count(dd) from t where dd = a.dd group by dd) ee from t a
insert t
select '0002','USER0',12
union all
select '5260','USER2',10
union all
select '5260','USER2',10
union all
select '0002','USER1',12
union all
select '0002','USER1',12
union all
select '5260','USER3',10
union all
select '5260','USER4',10
union all
select '5260','USER4',10 select a.aa,a.cc,a.dd,(select dd/count(dd) from t where dd = a.dd group by dd) ee from t a
解决方案 »
- 请教关于时间方面的sql语句
- 主键表?外键表?咳咳,大侠们,我糊涂了。。
- 复杂的存储过程。中高级的水平的朋友请进
- power designer中,怎么删除相同表结构的表
- 弱弱的问一下:在SQL存储过程里。查询语句怎么用变理本作字段名或表名,有没有变通的方法。
- 查询数据库中的表
- Java中怎么给SqlServer中的表创建触发器?
- 企业管理器中看不到系统数据库,而查询分析器中能看到,怎样才能看到呢?
- 急,再线等候!!!!
- 使用ACCESS数据库,如何在运行时建立一个小数位为两位的数据表字段?
- 问题没解决,再问关于数据的复制技术,请高手帮忙.
- SQL Server 2000 的问题,急急急!!!!
insert T select '0002', 'USER0', 12.0, 0.0
union all select '5260', 'USER2', 10.0, 0.0
union all select '5260', 'USER2', 10.0, 0.0
union all select '0002', 'USER1', 12.0, 0.0
union all select '0002', 'USER1', 12.0, 0.0
union all select '5260', 'USER3', 10.0, 0.0
union all select '5260', 'USER4', 10.0, 0.0
union all select '5260', 'USER4', 10.0, 0.0 select AA, CC, DD,
EE=cast(DD as int)/(select count(*) from T where AA=tmp.AA)
from T as tmp--result
AA CC DD EE
---------- ---------- ------------ -----------
0002 USER0 12.0 4
5260 USER2 10.0 2
5260 USER2 10.0 2
0002 USER1 12.0 4
0002 USER1 12.0 4
5260 USER3 10.0 2
5260 USER4 10.0 2
5260 USER4 10.0 2(8 row(s) affected)
insert T select '0002', 'USER0', 12.0, 0.0
union all select '5260', 'USER2', 10.0, 0.0
union all select '5260', 'USER2', 10.0, 0.0
union all select '0002', 'USER1', 12.0, 0.0
union all select '0002', 'USER1', 12.0, 0.0
union all select '5260', 'USER3', 10.0, 0.0
union all select '5260', 'USER4', 10.0, 0.0
union all select '5260', 'USER4', 10.0, 0.0select distinct AA, CC, DD,
EE=cast(DD as int)/(select count(*) from T where AA=tmp.AA)
from T
具体的sql语句就是这样的,和他们的一样!
select AA, CC, DD,
EE=cast(DD as int)/(select count(*) from T where AA=tmp.AA )
from T as tmp