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

SQL transformation forespørgsel

WITH    q AS
        (
        SELECT  *, ROW_NUMBER() OVER (PARTITION BY parentID ORDER BY StartTime) AS rn
        FROM    mytable
        )
SELECT  qb.ParentID,
        qb.StartTime AS BreakfastStart, qb.EndTime AS BreakfastEnd,
        ql.StartTime AS LunchStart, ql.EndTime AS LunchEnd,
        qd.StartTime AS DinnerStart, qd.EndTime AS DinnerEnd
FROM    q qb
LEFT JOIN
        q ql
ON      ql.parentID = qb.parentID
        AND ql.rn = 2
LEFT JOIN
        q qd
ON      qd.parentID = qb.parentID
        AND qd.rn = 3
WHERE   qb.rn = 1



  1. hvordan downloader man blob-baseret fil fra MySQL-databasen i PHP?

  2. formålet med det maksimale antal i php og mysql

  3. hvordan man kun opdaterer det første tegn i SQL Server

  4. Failover &Failback på Amazon RDS