教你快速掌握Sybase IQ常用分析型函数

  • 来源: 赛迪网 作者: 若水   2008-04-28/10:20
  • 很多人都知道,Sybase IQ是高性能的数据仓库引擎,在SQL编程方面,它也引入了许多新的特性,分析型函数就是其中之一。常用的分析型函数如下:Grouping( ), Variance( ),StdDev( ), Rank( ), Dense_Rank( ),Percentile_Disc( ), Percentile_Count( ), Ntile( )等。

    在实际的工作和学习中,使用以上的分析型函数,可以为用户的前端编程或者后台SQL编程带来极大的方便。

    以上函数的简单示例如下:

     

     

    select top 10 taxpayercode ,sum(mny_seze) as mny_seze_sukm, sum(mny_srze) as mny_srze_sum, DENSE_RANK() over( order by mny_srze_sum desc) as rank_all

    from tqa_f_nsrqusb where id_mth=200702

    group by taxpayercode

    order by rank_all

     

     

    select taxpayercode ,sum(mny_seze) as mny_seze_sukm,sum(mny_srze) as mny_srze_sum

    from tqa_f_nsrqusb where id_mth=200702

    group by taxpayercode order by mny_srze_sum desc

     

     

    select top 10 taxpayercode ,sum(seze) as seze , NTILE(2) over ( order by seze desc) as ntile

    from whtaxpayertaxbook where yr_sb=2005 and mth_sb=1

    group by taxpayercode

    order by seze

     

    select top 10 taxpayercode, sum(seze) as seze, percent_rank() over (order by seze desc) as per_rank

    from whtaxpayertaxbook where yr_sb=2005 and mth_sb=1

    group by taxpayercode

    order by seze

     

    select top 10 taxpayercode, sum(seze) as seze, rank() over (order by seze desc) as per_rank

    from whtaxpayertaxbook where yr_sb=2005 and mth_sb=1

    group by taxpayercode

    order by seze

    注:在Oracle数据库9i以上的版本中也有类似的分析型函数,实现的功能也与此示例相似。


    评论 {{userinfo.comments}}

    {{money}}

    {{question.question}}

    A {{question.A}}
    B {{question.B}}
    C {{question.C}}
    D {{question.D}}
    提交

    驱动号 更多