我有一个项目表(project)和一个用户表(user)
projectproject_id first_person second_person third_person
33 12 78 65user
user_id user_name
12 组长
78 处长
65 主任
我想查询project表里project_id=33的first_person,second_person,third_person的名字(是user_name,不是user_id),请问用一个sql语句怎样写出来。谢谢了。
projectproject_id first_person second_person third_person
33 12 78 65user
user_id user_name
12 组长
78 处长
65 主任
我想查询project表里project_id=33的first_person,second_person,third_person的名字(是user_name,不是user_id),请问用一个sql语句怎样写出来。谢谢了。
(select user_name from [user] where user_id=p.second_person) as second_person,
(select user_name from [user] where user_id=p.third_person) as third_person
from project p
where project_id=33
first_person = (select user_name from user b where b.user_id = a.first_person),
second_person = (select user_name from user b where b.user_id = a.second_person),
third_person = (select user_name from user b where b.user_id = a.third_person)
from project a
where a.project_id=33
b.user_name,
c.user_name,
d.user_name
from project a,user b,user c,user d
where a.first_person = b.user_id
and a.second_person = c.user_id
and a.third_person = d.user_id
b.user_name,
c.user_name,
d.user_name
from project a,user b,user c,user d
where a.first_person = b.user_id
and a.second_person = c.user_id
and a.third_person = d.user_id
select a.project_id ,
first_person = (select [user_name] from [user] b where b.[user_id] = a.first_person),
second_person = (select [user_name] from [user] b where b.[user_id] = a.second_person),
third_person = (select [user_name] from [user] b where b.[user_id] = a.third_person)
from project a
where a.project_id=33