我一直试图在最后一小时内解决这个问题。我的大学导师给我这个问题,我不知道该怎么做。
问题是:
显示英国所有已执行一个方向的县
这是db和tables:
CITY (Name, County, Country)
THEATRE (Name, City, County, Capacity)
SHOW (Title, Artist, Venue, Attendance)
这是我的答案:
SELECT country from theatre
INNER JOIN show
ON theatre.name = show.venue
WHERE artist = 'one direction'
AND county=(
SELECT country FROM theatre
INNER JOIN city
ON theatre.city = city.name
WHERE city.country = 'UK'
)
我关闭了吗?
答案 0 :(得分:2)
SELECT DISTINCT
THEATRE.County AS CountyFromTheatre,
CITY.County AS CountyFromCity,
FROM SHOW
INNER JOIN THEATRE ON THEATRE.NAME=`SHOW`.Venue
INNER JOIN CITY ON CITY.NAME=THETARE.City
WHERE `SHOW`.Artist='one direction'
AND CITY.Country='UK'
观察#1:注意SHOW上的反叛 - 使用保留字作为表名通常是不好的风格。
观察#2:CITY表和THEATER都有县。这是一个糟糕的设计 - 想象一个有“A”县的地方,而城市有“B”县