我必须显示由推荐人推荐的所有与顾客名字相同的顾客。
答案 0 :(得分:1)
您可以尝试此查询
select cust.*, cust_ref.*
from customers cust,
referred cust_ref
where cust_ref.lastname = cust.lastname
注意:您可以根据需要选择字段。
我希望它会用到。
答案 1 :(得分:1)
您可以将self-join
用作
select c1.customer#, c1.lastname, c1.city, c1.zip, c1.referred
from customers c1
join customers c2
on c1.customer# = c2.referred
and c1.lastname = c2.lastname;
customer# lastname city zip referred
--------- -------- ----------- ------ ---------
1003 SMITH TALLAHASSEE 32306 NULL