gpt4 book ai didi

mysql - 嵌套sql怎么办?

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

我的输入只是用户ID。如何组合三个表来获取区域名称。我很确定我的语法是正确的

TABLE NAME: userinfo userid PRIMARY KEY

TABLE NAME: userinfo_attarea employee_id FOREIGN KEY userid REFERENCE userinfo area_id FOREIGN KEY area_id REFERENCE personnel area

TABLE NAME: personnel area area_id PRIMARY KEY areaname

我尝试过但失败了,

SELECT areaname FROM userinfo a
INNER JOIN (SELECT *FROM userinfo_attarea b
INNER JOIN SELECT *FROM personnel_area c
ON b.areaid = c.areaid
) b ON a.userid = b.employee_id;

最佳答案

我认为这个查询会对您有所帮助

select areaname from personel_area pa inner join
userinfo_attarea ut on pa.area_id=ut.area_id
inner join userinfo ui on ut.employee_id=ui.userid

关于mysql - 嵌套sql怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51438904/

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