mysql - 如果 Id,如何获取名称
问题描述
我想获取所有数据,但不是主管和团队负责人中的 id 我想获取他们的姓名或电子邮件 ID
前任
如果我获取 id 8 数据,它应该是这样的:
id -> 8
user_name -> ag2
password -> 121212
email -> ag2@ag.com
mobile->21341234
superwisor -> kk(user_name of Id 1)
teamleader -> tl2(user_name of id 4)
解决方案
您需要self join
按如下方式使用:
Select e.id, e.user_name, e.email, e.password, e.mobile,
s.user_name as superwisor, t.user_name as team_leader
From your_table e
Left join your_table s on s.id = e.superwisor
Left join your_table t on t.id = e.teamleader;
推荐阅读
- reactjs - 通过创建动态选择来响应 useRef 钩子
- python-3.x - 在不到 1 秒的时间内计算出大数的算术序列的总结果
- python - 允许用户在 DJango 中拥有他们的产品
- excel - 当值为零时隐藏列中的单元格
- sql - 翻译 unix 风格的按位整数的 Oracle 查询
- css - 如何使用 React 和 Material io 修复 Ipad 或移动设备上的焦点背景颜色
- string - 如何根据给定的要求拆分/标记字符串?
- reactjs - React Lifting State Up - 为什么在父级重新渲染时不调用子级的构造函数?
- c++ - 我在 Linux VSCode (gcc) 和 Windows Clion (visual c++) 上的相同代码有不同的输出
- html - 响应方块的动态网格: