如何从多列中选择不同的列
你好 我确信有人对这种操作有疑问,但我似乎无法理解它。
我有一个像这样的表:
product_id | saved_by | deleted_by | accepted_by | published_by
-----------+----------+------------+-------------+-------------
1 | user1 | | user1 |
-----------+----------+------------+-------------+-------------
2 | | user2 | |
-----------+----------+------------+-------------+-------------
3 | user2 | | | user3
-----------+----------+------------+-------------+-------------
4 | | | user1 | user4
-----------+----------+------------+-------------+-------------
我正在尝试创建一个查询,该查询将选择这些字段中的所有用户,从而明显地产生如下结果:
users
------
user1
user2
user3
user4
有指针吗?
Hi
I'm sure there's query for this kind of operation, but I just can't seem to get it.
I have a table like this:
product_id | saved_by | deleted_by | accepted_by | published_by
-----------+----------+------------+-------------+-------------
1 | user1 | | user1 |
-----------+----------+------------+-------------+-------------
2 | | user2 | |
-----------+----------+------------+-------------+-------------
3 | user2 | | | user3
-----------+----------+------------+-------------+-------------
4 | | | user1 | user4
-----------+----------+------------+-------------+-------------
And I'm trying to create a query that would select all the users in those fields distinctly resulting in something like this:
users
------
user1
user2
user3
user4
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先想到的是对列进行 UNION:
http://postgresql.org /docs/9.0/interactive/sql-select.html
作为旁注,如果此数据已标准化,那么按照您想要的方式获取数据会容易得多。
First thing that comes to mind is to UNION the columns:
http://postgresql.org/docs/9.0/interactive/sql-select.html
As a side note if this data was normalized it would be much easier to get the data the way you want.