有一组数字 0,1,2,3,4,5,6,78845456723452342341123412341234123412346345634567456745474567.现在要选出百分比在为1%的数字,基础数为0,1,2,3,4,5,6,7,8,9

解决方案 »

  1.   


    declare @hh table (number int  ,pre float )
    insert into @hh (number)
    select 2 union all
    select 4 union all
    select 5 union all
    select 6 union all
    select 7 union all
    select 8 union all
    select 8 union all
    select 3 union all
    select 2 union all
    select 2 union all
    select 34 union all
    select 3 union all
    select 6 union all
    select 6
    --select * from @hh
    DECLARE @hhcount float
    SELECT @hhcount=count(number) FROM @hh
    UPDATE @hh
    SET pre =number/@hhcount;
    select * from @hh
      

  2.   

    number      pre
    ----------- ----------------------
    2           0.142857142857143
    4           0.285714285714286
    5           0.357142857142857
    6           0.428571428571429
    7           0.5
    8           0.571428571428571
    8           0.571428571428571
    3           0.214285714285714
    2           0.142857142857143
    2           0.142857142857143
    34          2.42857142857143
    3           0.214285714285714
    6           0.428571428571429
    6           0.428571428571429
      

  3.   

    to himetale  :  出现几率为1%  
    to maco_wang :   你给的那个我还得看看 ,没弄明白呢 
      

  4.   


    declare @dd table (关键词 varchar(4))
    insert into @dd
    select '诗词' union all
    select '诗词' union all
    select '诗词' union all
    select '文章' union all
    select '文章' union all
    select '生活' union all
    select '品味'

    declare @hh varchar(2000)
    set @hh='生活,文章';
    SELECT charindex(',',@hh);
    SELECT substring(@hh,1,charindex(',',@hh)-1);
    SELECT substring (@hh,charindex(',',@hh)+1 ,len(@hh));
    SELECT count(*) FROM @dd WHERE 关键词=substring(@hh,1,charindex(',',@hh)-1);
    SELECT count(*) FROM @dd WHERE 关键词=substring (@hh,charindex(',',@hh)+1 ,len(@hh));