Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE FUNCTION dbo.udf_GetColonistsCount(@planetName VARCHAR(30))
- RETURNS TABLE
- AS
- RETURN
- (SELECT
- p.Name AS [PlanetName],
- COUNT(tc.ColonistId) AS [Count]
- FROM Planets AS p
- JOIN Spaceports AS sp ON sp.PlanetId = p.Id
- JOIN Journeys AS j ON j.DestinationSpaceportId = sp.Id
- JOIN TravelCards AS tc ON tc.JourneyId = j.Id
- WHERE p.Name = @planetName
- GROUP BY p.Name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement