题目:
思路:
这道题是说找到没有order的客户,能立刻想到用到的方法是:not exists
exists: 为真就返回结果集
not exists: 为真就不返回结果集
代码:
select 1 from table 的结果是临时得到1列 (列的值为1),其行数为表的记录数 (行数)
1 是常量 (可以为任意数值)
SELECT C.Name as Customers
FROM Customers C
WHERE not exists(
select 1
from Orders O
where C.Id = O.CustomerId
)
结果:
如果有什么其他方法,请留言吧~~
觉得不错,就点赞或者关注
谢谢~ ~