做个了数据查询 结果为
姓名 成绩
李四 120   
张明 110
王小牛 128
王小丫 80最终要得到的结果为姓名 成绩  所占总分数百分比
李四 120    27.39%
张明 110    25.11%
王小牛 128    29.22%
王小丫 80     18.26%create table #cjb
(xm char(8) null,
 cj int 
)
insert into #cjb
(xm,cj)
select '李四',120
union all
select '张明',110
union all
select '王小牛',128
union all
select '王小丫',80
或者 用 fast report 报表 作出那个最终结果也可以

解决方案 »

  1.   

    create table #cjb 
    (xm char(8) null, 
    cj int 

    insert into #cjb 
    (xm,cj) 
    select '李四',120 
    union all 
    select '张明',110 
    union all 
    select '王小牛',128 
    union all 
    select '王小丫',80 select *,
    所占总分数百分比=ltrim(cast(cj*100./(select sum(cj) from #cjb) as dec(9,2)))+'%'
    from #cjb
    /*
    xm       cj          所占总分数百分比
    -------- ----------- ------------------------------------------
    李四       120         27.40%
    张明       110         25.11%
    王小牛      128         29.22%
    王小丫      80          18.26%(4 行受影响)
    */
      

  2.   


    create table #cjb 
    (xm char(8) null, 
    cj int 

    insert into #cjb 
    (xm,cj) 
    select '李四',120 
    union all 
    select '张明',110 
    union all 
    select '王小牛',128 
    union all 
    select '王小丫',80 
    select a.xm as 姓名,cj as 成绩,  所占总分数百分比=ltrim(cast(cj*100.0/(select sum(cj)from #cjb)as decimal(10,2)))+'%'
    from #cjb adrop table #cjb姓名       成绩          所占总分数百分比
    -------- ----------- ------------------------------------------
    李四       120         27.40%
    张明       110         25.11%
    王小牛      128         29.22%
    王小丫      80          18.26%(4 行受影响)
      

  3.   

    select 
      a.xm as 姓名,
      cj as 成绩, 
      ltrim(cast(cj*100./(select sum(cj) from #cjb) as dec(9,2)))+'%' as 所占总分数百分比
    from 
      #cjb