我有一组数据,请问sql排序语句如何写?及如何实现表的存储?谢谢!
 年份  流量    序号 排序后的流量(大->小) 频率p
1886  16400     1     18700                0.88
1917  18700     2     17400                1.75
1931  15700     3     16400                2.63
1947  15000     4     15700                3.51
1955  17400     5     15000                4.39其中p=m/n+1  

解决方案 »

  1.   

    select *
    from T
    order by 流量 desc
      

  2.   

    update T
    set p = m/n+1
      

  3.   

    select
    *,
    (select count(1) from table1 where 流量>=t1.流量)as 排序后的流量,
    cast(流量*1.0/(select count(1) from table1 where 流量>=t1.流量) as decimal(18,2)) as 频率p
    from 
    Table1 t1
      

  4.   

    改改
    select
    *,
    isnull((select max(流量) from table1 where 流量<t1.流量),0)as 排序后的流量,
    cast(流量*1.0/(select max(流量)  from table1 where 流量<t1.流量) as decimal(18,2)) as 频率p
    from 
    Table1 t1
      

  5.   

    好像明白了这样:
    declare @T table([年份] int,[流量] int, [序号] int)
    insert @T select 1886,     16400,           1
    insert @T select 1917,     18700,           2
    insert @T select 1931,     15700,           3
    insert @T select 1947,     15000,           4
    insert @T select 1955,     17400,           5select
    a.*,
    b.[流量] as [排序后的流量],
    cast( a.[流量]*1.0/b.[流量] as decimal(18,2))  as 频率p
    from 
    @T a
    join
    (select *,(select count(1) from @T where 流量>=t1.流量) as con from  @T t1)b
    on a.[序号]=b.con/*(所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)年份          流量          序号          排序后的流量      频率p                  
    ----------- ----------- ----------- ----------- -------------------- 
    1886        16400       1           18700       .88
    1917        18700       2           17400       1.07
    1931        15700       3           16400       .96
    1947        15000       4           15700       .96
    1955        17400       5           15000       1.16(所影响的行数为 5 行)
    */