不用存储过程写行不行?不行的话你自己改了select f_Year,f_Month,
case(f_Quantity as numeric(10,2))*f_Price/(select sum(f_Quantity*f_Price) from t1 where f_Year=a.f_Year) as f_Pro, f_Price
from t1 a
where f_Month  =1还是:
select f_Year,f_Month,
case(f_Quantity as numeric(10,2))/(select sum(f_Quantity ) from t1 where f_Year=a.f_Year) as f_Pro, f_Price
from t1 a
where f_Month  =1
没细算,哪个对不知道,全错了就不管了哈,哈哈,哈哈哈......

解决方案 »

  1.   

    其中f_Pro是该年的1月占全年的比例? 不明白
    select a.f_year,
           b.f_month,
           [f_pro]=(select sum(f_quantity*f_price) from ttt c where c.f_year=a.f_year)/
           (select f_quantity*f_price from ttt d where d.f_year=a.f_year and d.f_month=1),
           b.f_price
    from
    (select f_year from ttt group by f_year) a
    join
    ttt b
    on a.f_year=b.f_year
    where b.f_month=1
      

  2.   


    刚才搞错啦
    select a.f_year,
           b.f_month,
           [f_pro]=(select f_quantity*f_price from ttt d where d.f_year=a.f_year and d.f_month=1)/
           (select sum(f_quantity*f_price) from ttt c where c.f_year=a.f_year),
           b.f_price
    from
    (select f_year from ttt group by f_year) a
    join
    ttt b
    on a.f_year=b.f_year
    where b.f_month=1
      

  3.   

    ----测试结果
    f_year      f_month     f_pro                                    f_price      
    ----------- ----------- ---------------------------------------- ------------ 
    2000        1           .05555555555555555                       .30
    2001        1           .07272727272727272                       .40(所影响的行数为 2 行)
      

  4.   

    CREATE PROCEDURE shouru_p
    @month varchar(10)
    as
    select distinct (b.s_year),b.s_month,cast(s_qty as decimal(10,4))/(select sum(s_qty ) from shouru  as c where c.s_year=a.s_year )as f_pro,b.s_price  from shouru as b
    join (select s_year from shouru group by s_year) as a
    on a.s_year=b.s_year
    where  b. s_month=@month
    GO