Kodewick
开始学 →
入门←→0 / 70

没有就写 none

#046入门NULL查询约 3 分钟

前台要打印主人名单,电话一栏空着不好看。从 owners 表里选出 name 和电话两列;电话是空(NULL)的,显示成 'none'。

用到的表
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
-- 在这里写:把下面的 phone 换成 COALESCE(phone, 'none')(写在这里,删掉下面那条)
SELECT name, phone
FROM owners;
Ctrl + Enter 也能运行
结果

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