Congestion Charging

From SQLZOO
Revision as of 13:45, 19 July 2012 by Connor (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Congestion charging database

Graduated questions

  • [[Congestion Easy |Easy questions: 1..5
  • [[Congestion Medium |Medium questions: 6..10
  • [[Congestion Hard |Hard questions: 11..15

ER diagram for the Congestion charging database:

File:/pics/er5.gif

camera(id, perim)

keeper(id, name, address)

vehicle(id, keeper)

image(camera, whn, reg)

permit(reg, sDate, chargeType)

Sample query

List the vehicles for which 'Strenuous, Sam' is the registered keeper. The link between Keepers and Vehicles is via the foreign key specified in the CREATE TABLE vehicle statement. Note the line:

 ,FOREIGN KEY(keeper) REFERENCES keeper(id)

This will be the basis of our join condition.

SELECT vehicle.id
  FROM vehicle JOIN keeper
        ON vehicle.keeper = keeper.id
   WHERE keeper.name = 'Strenuous, Sam'
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense