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

Drej flere rækker

Du er 90 % af vejen dertil:

with cte as (
    select 
        id, 
        case [key] 
            when 'A' 
            then str_val 
        end as A, 
        case [key] 
            when 'B' 
            then str_val 
        end as B, 
        case [key] 
            when 'C' 
            then date_val 
        end as C, 
        case [key] 
            when 'D' 
            then num_val 
        end as D,
        case [key] 
            when 'E' 
            then str_val 
        end as E 
    from test_table
)
select id, max(A) as A, max(B) as B, max(C) as C, max(D) as D, max(E) as E
from cte
group by id


  1. Sådan beregnes daglige aktive brugere (DAU) i MySQL

  2. MySQL Fire-And-Forget INSERT / UPDATE / DELETE - brug af mysql_unbuffered_query tilrådeligt?

  3. Sådan ser du PL/SQL Stored Function body i Oracle

  4. Udfør sp_msforeachdb i en Java-applikation