自加入表中
CustID Name ReferredBy
1 Neeta Sayam
2 Dolly Dilly 1
3 Meena Kimi 2
查找由其他人推荐的所有客户的姓名。
输出应该是 dolly dilly 和 meena kimi。
我已经成功找到通过查询推荐其他人的客户
SELECT c1.name FROM Customer c1 JOIN Customer c2 ON c1.custid=c2. ReferredBy
CustID Name ReferredBy
1 Neeta Sayam
2 Dolly Dilly 1
3 Meena Kimi 2
Find the names of all customers who are referred by others.
the output should be dolly dilly and meena kimi.
I have succesfully found out for customers who have reffred others by query
SELECT c1.name FROM Customer c1 JOIN Customer c2 ON c1.custid=c2. ReferredBy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非我错过了什么:
Unless I'm missing something:
有很多方法可以实现您想要的目标,但一个有趣的是使用 CTE,因为它允许您按级别获取参考,例如在您的情况下,零级将是没有参考的
Neeta syam
,第一级是dolly dilly
和meena kimi
。以下查询将返回dolly dilly
和meena kimi
,它们位于where reference = 1
指定的一级,如下所示:There are a lot of ways to achieve what you want, but one interesting is using CTE because it allows you to get reference by level, for example in your case level zero will be
Neeta syam
that has no reference, level one isdolly dilly
andmeena kimi
. The following query will returndolly dilly
andmeena kimi
which are in the level one specified bywhere reference = 1
like so: