select 列1*100.0/(列1+列2+列3) 列1 的百分比,
列2*100.0/(列1+列2+列3) 列2 的百分比,
列3*100.0/(列1+列2+列3) 列3 的百分比
from 表
where 年=2005

解决方案 »

  1.   

    select 列1*100.0/(列1+列2+列3) 列1 的百分比,
    列2*100.0/(列1+列2+列3) 列2 的百分比,
    列3*100.0/(列1+列2+列3) 列3 的百分比
    from 表
    where 年=2005
      

  2.   

    有時候該COPY的時候還是要COPY的。
      

  3.   

    --建立测试环境
    if exists(select * from sysobjects where xtype ='u' and name='TestC')
    drop table TestC
    go
    create table TestC
    (
    C_year varchar(20),
    C_1 int,
    C_2 int,
    C_3 int
    )
    insert into TestC select '2004',11,12,13
    union all select '2004',14,20,33
    union all select '2005',13,22,44
    union all select '2005',19,29,49
    --测试
    select C_year, sum(C_1)*100/(sum(C_1)+sum(C_2)+sum(C_3)) as C1, 
    sum(C_2)*100/(sum(C_1)+sum(C_2)+sum(C_3)) as C2,
    sum(C_3)*100/(sum(C_1)+sum(C_2)+sum(C_3)) as C3 
    from TestC group by C_Year
    --删除
    drop table TestC