SQL按不同列选择整个行 [英] SQL Select Entire Row by Distinct Columns
本文介绍了SQL按不同列选择整个行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一条sql语句,该语句允许我从oracle数据库中选择整行,但可以通过不同的列进行选择.这是一个简化的数据库:
I need an sql statement which will allow me to select an entire row from oracle database, but by distinct columns. Here is a simplified database:
Project_Num Title Category
0 Project 1 Admin
0 Project 1 Development
1 Project 2 Admin
2 Project 3 Development
我需要我的语句返回以下结果集:
I need my statement to return the following result set:
0 Project 1 Admin
1 Project 2 Admin
2 Project 3 Development
因此,将根据每个项目的project_num和title是否唯一来返回每个项目.如果一个项目有2个以上类别不同的条目,那么我只需要选择一次该项目(为该项目选择哪个条目都没关系).
So each project is returned based on whether its project_num and title are unique. If a project has 2+ entries where its category is different, I need to only select that project once (it doesn't matter which entry I select for that project).
有人可以帮我吗?
推荐答案
SELECT Project_Num, Title, MIN(Category) AS Category
FROM MyTable
GROUP BY Project_Num, Title;
这篇关于SQL按不同列选择整个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文