gpt4 book ai didi

mysql - 同时获取2个相同的字段

转载 作者:行者123 更新时间:2023-11-29 13:47:13 25 4
gpt4 key购买 nike

我有下面 3 个表。 (示例)(mySql 脚本)

客户

  • cust_id
  • 客户名称
  • 用户 ID
  • user_id_2

用户

  • 用户 ID
  • em_id

员工

  • em_id
  • em_name

如何通过交叉调用user_idem_name字段和user_id_2em_name字段>user 表与 join 同时进行?

最佳答案

试试这个

SELECT  q1.* ,
q2.em_name AS 'em_name_2'
FROM (SELECT c.cust_id ,
c.cust_name ,
c.user_id ,
c.user_id_2 ,
e.em_name
FROM dbo.customer AS c
INNER JOIN dbo.[user] AS u ON c.user_id = u.user_id
INNER JOIN dbo.employee AS e ON u.em_id = e.em_id
) q1
CROSS JOIN
( SELECT e.em_id ,
e.em_name
FROM dbo.customer AS c
INNER JOIN dbo.[user] AS u ON c.user_id_2 = u.user_id
INNER JOIN dbo.employee AS e ON u.em_id = e.em_id
) q2

关于mysql - 同时获取2个相同的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17228939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com