zoukankan      html  css  js  c++  java
  • SQL分组编号

    IF OBJECT_ID(N'tempdb..#tmp') IS NOT NULL

        DROP TABLE #tmp

       

    CREATE TABLE #tmp ( aaa VARCHAR(10), bbb INT )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '11111', 5 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '11111', 3 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '11111', 2 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '44444', 1 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '44444', 3 )

    SELECT * FROM #tmp

    select aaa,bbb,row_number()over(partition by aaa order by aaa) rn from #tmp

    IF OBJECT_ID(N'tempdb..#tmp') IS NOT NULL

        DROP TABLE #tmp

       

    CREATE TABLE #tmp ( aaa VARCHAR(10), bbb INT )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '11111', 5 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '22222', 3 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '33333', 2 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '44444', 1 )

    INSERT  INTO #tmp

            ( aaa, bbb )

    VALUES  ( '55555', 3 )

    SELECT  *

    FROM    #tmp

    SELECT  b.aaa ,

            b.bbb ,

            a.number

    FROM    #tmp b

            JOIN master.dbo.spt_values a ON 1 = 1

    WHERE   a.number > 0

            AND a.number <= 2000

            AND a.type = 'p'

            AND a.number <= b.bbb

  • 相关阅读:
    [BZOJ]2959: 长跑
    http状态码 超详细
    mysql注入常用函数
    tomcat7远程代码执行 ImageMagick 命令执行漏洞
    kali安装redis
    反序列化
    CSP 之dvwa
    token防爆破?
    变量覆盖
    安全狗绕过
  • 原文地址:https://www.cnblogs.com/anranstl/p/5241272.html
Copyright © 2011-2022 走看看