尝试选择多列,其中一列是唯一的 [英] Trying to select multiple columns where one is unique
本文介绍了尝试选择多列,其中一列是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从其中一列是唯一的表中选择几列.select 语句看起来像这样:
I am trying to select several columns from a table where one of the columns is unique. The select statement looks something like this:
select a, distinct b, c, d
from mytable
表格看起来像这样:
| a | b | c | d | e |...
|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5
| 1 | 2 | 3 | 4 | 6
| 2 | 5 | 7 | 1 | 9
| 7 | 3 | 8 | 6 | 4
| 7 | 3 | 8 | 6 | 7
所以查询应该返回如下内容:
So the query should return something like this:
| a | b | c | d |
|---|---|---|---|
| 1 | 2 | 3 | 4
| 2 | 5 | 7 | 1
| 7 | 3 | 8 | 6
我只想删除 b 重复的所有行.
I just want to remove all of the rows where b is duplicated.
在重复 b 值的情况下,我想选择哪一行似乎有些混乱.我不在乎,因为 a、c 和 d 应该(但不能保证)相同.
There seems to be some confusion about which row I want to be selected in the case of duplicate b values. I don't care because the a, c, and d should (but are not guaranteed to) be the same.
推荐答案
试试这个
SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY b ORDER BY a) NO
,* FROM TableName) AS T1 WHERE NO = 1
这篇关于尝试选择多列,其中一列是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文