Kodewick
开始学 →
小挑战←→0 / 70

奥斯陆最老的两只

#066小挑战连接排序和分页约 6 分钟

宠物医院要给 Oslo 的老宠物寄体检提醒。只看主人 city 是 'Oslo' 的宠物,按 age 从大到小排,只要前 2 只。要宠物名、主人名、age 三列。

用到的表
owners
idnamecityphone
1LenaOslo555-0101
2MarcoRomeNULL
3PriyaOslo555-0103
4OmarCairoNULL
5SofiaRome555-0105
5 行
pets
idnamekindageweightowner_id
1Biscuitdog3121
2Mochicat541
3Pepperdog8202
4Nemofish1NULL3
5Lunacat233
6Rexdog1130NULL
7Kiwibird4NULL5
8Tofucat75NULL
8 行
query.sql
SELECT pets.name, owners.name, pets.age
FROM pets
JOIN owners ON pets.owner_id = owners.id
-- 在这里写:WHERE 留下 Oslo 的,按 pets.age 从大到小,LIMIT 2
;
Ctrl + Enter 也能运行
结果

写好了先点「运行」看看结果,没问题再点「提交」。