【发布时间】:2023-03-10 14:13:01
【问题描述】:
我们正在开发类似社交网站的东西。我有任务要做 “跟我来”功能。我们网站的对象是用户、团队、公司、渠道和群组(请不要问为什么会有群组和团队——这对我来说也很复杂,但是团队与用户的才能有关)
用户、团队、频道、公司和群组都有自己的表格。
我有一个查询,可以让我找到所有像这样的追随者领导
select
--fo.leader_id,
--fo.leader_type,
us.name as user_name,
co.name as company_name,
ch.title as channel_name,
gr.name as group_name,
tt.name as team_name
from
follow_up fo
left join users us
on (fo.leader_id = us.id and fo.leader_type = 'user')
left join companies co
on (fo.leader_id = co.user_id and fo.leader_type = 'company')
left join channels ch
on (fo.leader_id = ch.id and fo.leader_type = 'channel')
left join groups gr
on (fo.leader_id = gr.id and fo.leader_type = 'group')
left join talent_teams tt
on (fo.leader_id = tt.id and fo.leader_type = 'team')
where
follower_id = 83
我需要获取所有字段,例如:
- 用户名,
- 公司名称,
- 频道名称,
- 组名,
- 团队名称
作为 SELECT 产品中的一个字段。 我试图给它们起一个别名,但甲骨文给它编号。 请帮忙:)
【问题讨论】:
标签: sql oracle select join alias