USE tempdb
GO
CREATE TABLE Teams (
    LeagueID int ,
    Players int ,
    Points int ,
    Budget money ,
    RegistrationDate datetime ,
    Place int
)

-- To update the place based on the highest points, least budget and the 
-- recent registration date.
UPDATE t1
SET t1.Place = ( SELECT COUNT( * ) FROM Teams AS t2
                 WHERE t2.LeagueID = t1.LeagueID And
                       t2.Points <= t1.Points And
                       t2.Budget >= t1.Budget And
                       t2.RegistrationDate >= t1.RegistrationDate )
FROM Teams AS t1
WHERE t1.Players > 0
This page was last updated on May 01, 2006 04:28 PM.