sql >> Database teknologi >  >> RDS >> Oracle

Oracle SQL - DENSE_RANK

Som jeg forstod, er dette, hvad du har brug for:

select client_ID, status_id, from_date, to_date, 
       sum(start_of_group) over (order by client_ID, from_date) + 1 rank
  from (SELECT c.client_ID, c.status_id, c.from_date, c.to_date,
               case when lag(c.client_ID, 1, c.client_ID) over (order by c.client_ID, c.from_date) = c.client_ID 
                     and lag(c.status_id, 1, c.status_id) over (order by c.client_ID, c.from_date) = c.status_id
                    then 0 else 1 end start_of_group
          FROM client c)
 order by client_ID, from_date

SQLFiddle



  1. hvordan man udpakker PostgreSQL-forbindelsen fra IBM WSJdbc41Connection

  2. ATAN2() Funktion i Oracle

  3. Kan ikke bruge filterkolonner fra materialiseret visningslog på tabel

  4. reverse mysql_real_escape_string