在表中列出不同元组的不同方法是什么,高盛的原始问题说列出 10 种不同的方法,其中一种方法是使用DISTINCT。任何人都可以帮助我更多..
问问题
3137 次
4 回答
8
这里有四个。
GROUP BY <all_columns>
SELECT * FROM T INTERSECT SELECT * FROM T
SELECT * FROM T UNION SELECT * FROM T
SELECT * FROM T EXCEPT SELECT * FROM T WHERE 1 = 0
于 2012-06-26T10:46:24.833 回答
1
这是另一个(ANSI SQL)
select *
from (
select t.*,
row_number() over (partition by <all_columns>) as rn
from t
) t
where rn = 1
于 2012-06-26T10:50:05.167 回答
1
Set @row:=0;
select colname from (select colname,@row:=@row+1 as Row from tablename group by colname) as abc where Row>0;
这是通过为条目提供行名称的另一种方法。
于 2012-06-30T06:12:58.023 回答
0
1 使用计数和分组方式:
select f1,f2,count(*) from sample_table
group by f1,f2
having count(*) = 1;
2 使用公用表表达式:
;WITH CTE (Col1,Col2,Col3,DuplicateCount)
AS
(
SELECT Col1,Col2,Col3,
ROW_NUMBER() OVER(PARTITION BY Col1,Col2,Col3 ORDER BY Col1) AS DuplicateCount
FROM MyTable)
Select * from CTE Where DuplicateCount=1
于 2012-06-26T10:55:42.707 回答