sql >> Database teknologi >  >> RDS >> Sqlserver

Skift nummerkolonne

Dette er et problem med huller og øer.

Én tilgang. SQL Fiddle

WITH T1
     AS (SELECT *,
                ROW_NUMBER()
                  OVER (
                    PARTITION BY NAME
                    ORDER BY DATE) - ROW_NUMBER()
                                       OVER (
                                         PARTITION BY NAME, [PAY]
                                         ORDER BY DATE) AS Grp
         FROM   Table1),
     T2
     AS (SELECT *,
                MIN(DATE)
                  OVER (
                    PARTITION BY NAME, Grp) AS MinDate
         FROM   T1)
SELECT [NAME],
       [PAY],
       [DATE],
       DENSE_RANK()
         OVER (
           PARTITION BY NAME
           ORDER BY MinDate) AS CHANGEGROUP
FROM   T2
ORDER  BY NAME,
          MinDate 



  1. Hvordan får man en liste over databaser?

  2. Adgang nægtet for bruger 'root'@'localhost' (ved hjælp af adgangskode:JA) - Ingen privilegier?

  3. Sorter Multi-dimensional Array efter givne indekser - PHP?

  4. Udfyldning af en database uden kommandoen indlæs data