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

Enkel Pivot-prøve

SELECT MasterID, 
  [Basic Phone] = MAX([Basic Phone]),
  [Pixi] = MAX([Pixi]),
  [Blackberry] = MAX([Blackberry])
FROM
(
  SELECT MasterID, [Basic Phone],[Pixi],[Blackberry]
  FROM dbo.Services AS s
  PIVOT 
  (
    MAX([Status]) FOR [Type] IN ([Basic Phone],[Blackberry],[Pixi])
  ) AS p
) AS x
GROUP BY MasterID;

Eller mere enkelt - og kredit til @YS. for at påpege min redundans.

SELECT MasterID, 
  [Basic Phone],
  [Pixi],
  [Blackberry]
FROM
(
  SELECT MasterID, Status, Type FROM dbo.Services
)
AS s
PIVOT 
(
  MAX([Status]) FOR [Type] IN ([Basic Phone], [Blackberry], [Pixi])
) AS p;



  1. Periodisk InvalidCastException og serveren kunne ikke genoptage transaktionen med Linq

  2. postgreSQL.app :opret database

  3. hvordan man viser word-dokument i browser i localhost?

  4. Brug NEWID() til at oprette en unik værdi i SQL Server