我有一个包含这些列的表 ID,NAME,JOB 我想要的是选择表格中每个不同工作的一条记录
来自此表
ID NAME JOB
1 Juan Janitor
2 Jun Waiter
3 Jani Janitor
4 Jeni Bartender
这样的事情
ID NAME JOB
1 Juan Janitor
2 Jun Waiter
4 Jeni Bartender
使用distinct将允许我选择一个不同的列,但我想选择表中的每一列,任何人都知道如何?
答案 0 :(得分:3)
你可以试试这个
SELECT ID, NAME,JOB FROM
(
SELECT ID, NAME,JOB,Row_Number() Over (Partition BY NAME Order By ID) AS RN FROM `table1`
) AS T
WHERE RN = 1
答案 1 :(得分:1)
SELECT MIN(ID), NAME, JOB FROM `table`
Group by NAME, JOB
答案 2 :(得分:0)
- 仅获取Rnk = 1记录以获得所需的输出
SELECT ID,Rank() Over(Partition By Job Order By ID) As Rnk, Name,JOB
From EMP
答案 3 :(得分:0)
SELECT ID, NAME,JOB FROM
(
SELECT ID,Rank() Over(Partition By Job Order By ID) As jobRank, Name,JOB from #abhi
) AS TTable
WHERE jobRank = 1