如何在sql表中显示名称作为管理器名称 [英] how to display name as manager name in sql table

查看:65
本文介绍了如何在sql表中显示名称作为管理器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Id     Name    City   mgr_Id
----------------------------
1      abc     M      null
2      xyz     N      1
3      pqr     p      null
4      jkl     G      2







以上代码是我的sql表结构。我想在记录前面显示名称,表格中有Id作为参考(mgr_Id)。



表示xyz保留abc的引用。结果应该是下面的。








above code is my my sql table structure. i want to display Name in front of record which have the Id as reference(mgr_Id) in the table.

means xyz keep the reference of abc. the result should be folloing.


Id     Name    City   mgr_Id
----------------------------
1      abc     M      null
2      xyz     N      abc
3      pqr     p      null
4      jkl     G      syz



请帮助



代码块添加 - OriginalGriff [/ edit ]


please help

[edit]Code block added - OriginalGriff[/edit]

推荐答案

尝试:

Try:
SELECT a.Id, a.[NAME], a.City, b.[Name] AS Mgr FROM MyTable a
LEFT JOIN MyTable b ON a.Mgr_Id=b.Id


这篇关于如何在sql表中显示名称作为管理器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆