字段:cust_mgr_id (E_emp_info) 客户经理
next_pro(E_emp_info) 下一处理人
表二(E_emp_info)
字段: id,name
我想内连接查询表一的客户经理名 和 下一处理人名,请问能不能实现,若能够实现该这么写。
9 个解决方案
#1
BOM?
#2
inner join ...on....应该会用到子查询!
#3
SELECT E1.name AS 客户经理名, E2.name AS 下一处理人名
FROM L_loan_info AS L JOIN E_emp_info AS E1 ON cust_mgr_id=E1.id
JOIN E_emp_info AS E2 ON cust_mgr_id=E2.id
#4
下一处理人也是 关联E_emp_info的id
#5
SELECT E1.name AS 客户经理名, E2.name AS 下一处理人名
FROM L_loan_info AS L JOIN E_emp_info AS E1 ON cust_mgr_id=E1.id
JOIN E_emp_info AS E2 ON next_pro=E2.id
#6
select
(select name from E_emp_info m where m.id = n.cust_mgr_id),
(select name from E_emp_info m where m.id = n.next_pro)
from L_loan_info n
#7
5楼的可以用,6楼的以笛卡尔积的形式表现出来了,谢谢啦。
#8
是这个意思嘛!
;with LoanInfo(id,CustMgr)
AS
(
select name from E_emp_info e inner join L_loan_info l on e.id=l.cust_mgr_id
)
select li.name from L_loan_info l inner join E_emp_info e on l.next_pro=e.id inner join LoanInfo li on l.next_pro=li.id
;with LoanInfo(id,CustMgr)
AS
(
select name from E_emp_info e inner join L_loan_info l on e.id=l.cust_mgr_id
)
select li.name from L_loan_info l inner join E_emp_info e on l.next_pro=e.id inner join LoanInfo li on l.next_pro=li.id
#9
被骗了,我还以为有什么新的写法,非要登录才能看到。
#1
BOM?
#2
inner join ...on....应该会用到子查询!
#3
SELECT E1.name AS 客户经理名, E2.name AS 下一处理人名
FROM L_loan_info AS L JOIN E_emp_info AS E1 ON cust_mgr_id=E1.id
JOIN E_emp_info AS E2 ON cust_mgr_id=E2.id
#4
下一处理人也是 关联E_emp_info的id
#5
SELECT E1.name AS 客户经理名, E2.name AS 下一处理人名
FROM L_loan_info AS L JOIN E_emp_info AS E1 ON cust_mgr_id=E1.id
JOIN E_emp_info AS E2 ON next_pro=E2.id
#6
select
(select name from E_emp_info m where m.id = n.cust_mgr_id),
(select name from E_emp_info m where m.id = n.next_pro)
from L_loan_info n
#7
5楼的可以用,6楼的以笛卡尔积的形式表现出来了,谢谢啦。
#8
是这个意思嘛!
;with LoanInfo(id,CustMgr)
AS
(
select name from E_emp_info e inner join L_loan_info l on e.id=l.cust_mgr_id
)
select li.name from L_loan_info l inner join E_emp_info e on l.next_pro=e.id inner join LoanInfo li on l.next_pro=li.id
;with LoanInfo(id,CustMgr)
AS
(
select name from E_emp_info e inner join L_loan_info l on e.id=l.cust_mgr_id
)
select li.name from L_loan_info l inner join E_emp_info e on l.next_pro=e.id inner join LoanInfo li on l.next_pro=li.id
#9
被骗了,我还以为有什么新的写法,非要登录才能看到。