请尊重我是SQL编程中的新成员。我的问题是,我有3个不同的表,每个表都有不同的信息。
Table1:名称,userid,kycid,taskid,loanid,汇总
Table2:用户、合理性、kycid、taskid
Table3:合理性,合理性摘要
我想要一个显示如下结果的结果:名称、userid、kycid、taskid、loanid、汇总、合理性、合理性摘要。
每个理由都有相应的理由摘要:
示例: Reasonid: Reason汇总
1=要求取消
2=年龄不合格
发布于 2019-10-21 09:11:55
对于本例数据:
create table Table1 (Name varchar(50), userid int, kycid int, taskid int, loanid int, summary int);
create table Table2 (userid int, reasonid int, kycid int, taskid int);
create table Table3 (reasonid int, reasonsummary int);
insert into Table1 values('Name1', 1, 2, 3, 4, 5);
insert into Table1 values('Name2', 2, 3, 3, 4, 5);
insert into Table2 values(1, 33, 44, 55);
insert into Table2 values(3, 66, 44, 55);
insert into Table3 values(33, 55);
insert into Table3 values(55, 55);你可以试试这样的东西:
Select t1.Name
, t1.userid
, t1.kycid
, t1.taskid
, t1.loanid
, t1.summary
, t2.reasonid
, t3.reasonsummary
from table1 t1
left join table2 t2 on t1.userid = t2.userid
left join table3 t3 on t2.reasonid = t3.reasonid;但是要注意的是,所有其他的问题都是有效的,当你问一个问题的时候,你应该增加更多的细节。希望这能帮上忙。
下面是演示:http://sqlfiddle.com/#!9/5f736ce/1
发布于 2019-10-21 09:25:29
Select t1.Name
, t1.userid
, t1.kycid
, t1.taskid
, t1.loanid
, t1.summary
, t2.reasonid
, t3.reasonsummary
from table1 t1
, table2 t2
, table3 t3
where t1.userid=t2.userid
and t2.reasonid=t3.reasonid尝尝这个。
https://stackoverflow.com/questions/58482938
复制相似问题