列别名 oracle 10g
这看起来很简单,但我不明白如何执行此查询: 我有一个像这样的表 users:
user_id | name | role
1 | abc | a
2 | lol | b
3 | f | c
和一个表 usersprojects (包含用户和项目 PK)
projectid | userid
1 | 1
1 | 2
2 | 2
2 | 3
我如何选择所有用户列以及“分配”给项目“1”的布尔列别名
我想要这样的结果:
user_id | name | role | assigned
1 | abc | a | true
2 | lol | b | true
3 | f | c | false
查询不会是这样的:
Select user_id ,name, role,
(users.user_id in (Select user_id from usersprojects where projectid=1)
) assigned;
但是它不起作用...执行此查询的正确方法是什么?
This seems so simple but I can't understand how do I do this query:
I have a table users like this:
user_id | name | role
1 | abc | a
2 | lol | b
3 | f | c
and a table usersprojects (with user and project PKs)
projectid | userid
1 | 1
1 | 2
2 | 2
2 | 3
How could I select all users columns and also a boolean column alias "assigned" to project "1"
I would like a result like this:
user_id | name | role | assigned
1 | abc | a | true
2 | lol | b | true
3 | f | c | false
The query wouldn't be something like this:
Select user_id ,name, role,
(users.user_id in (Select user_id from usersprojects where projectid=1)
) assigned;
But it doesn't work... what is the right way to do this query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要一个左外连接。请记住,Oracle 中没有布尔数据类型。
You need a left outer join. Keep in mind that there is no
boolean
data type in Oracle.