一条 sql 问题,实在不知道如何解?

2022-11-21 09:34:09 +08:00
 shelken

用户

{
	id: 1,
	name: a
}

其他平台用户

{
	id: 4,
	userId: 1
	userType: 个人
}

{
	id: 5,
	userId: 1
	userType: 法人
}

用户表 1 对多 其他平台用户表 如何只查询了关联了个人的系统用户,以及只关联了法人的系统用户,以及同时关联个人和法人的系统用户?不使用 count 等函数方法,只用 where 条件或者 on 条件一条 sql 查询。

是否有解?

1136 次点击
所在节点    问与答
2 条回复
InTen
2022-11-21 09:45:55 +08:00
select u.id,u.name,u1.id as id1,u1.userType as userType1 ,u2.id as id2,u2.userType as userType2
from user
left join other_user u1 on user.id=u1.id and u1.userType='个人'
left join other_user u2 on user.id=u2.id and u1.userType='法人'
shelken
2022-11-21 10:57:01 +08:00
@InTen 谢谢,大佬

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/896702

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX