Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
U-SQL是否接受使用多个FIRST_值删除特定列中的重复项?_Sql_U Sql - Fatal编程技术网

U-SQL是否接受使用多个FIRST_值删除特定列中的重复项?

U-SQL是否接受使用多个FIRST_值删除特定列中的重复项?,sql,u-sql,Sql,U Sql,我有一个表,其中多行是重复的,因为两个日期列的值不同 我想知道这样在两列中使用第一个\u值来删除指定列上的重复项是否被接受: SELECT EmployeeName, FIRST_VALUE(StartDateTime) OVER(ORDER BY UpdatedDateTime DESC) AS StartDateTime, FIRST_VALUE(UpdatedDateTime) OVER(ORDER BY UpdatedDateTime DESC) AS UpdatedDateTim

我有一个表,其中多行是重复的,因为两个日期列的值不同

我想知道这样在两列中使用第一个\u值来删除指定列上的重复项是否被接受:

SELECT
 EmployeeName,
 FIRST_VALUE(StartDateTime) OVER(ORDER BY UpdatedDateTime DESC) AS StartDateTime,
 FIRST_VALUE(UpdatedDateTime) OVER(ORDER BY UpdatedDateTime DESC) AS UpdatedDateTime 
 FROM @Employees;

如果需要删除某些字段上的重复项,则需要使用
行号()
和CTE:

-- Sample data: dates duplicates
declare @t table (id int, dt date);
insert into @t values
(1, '2018-01-14'),
(1, '2018-01-14'),
(1, '2018-01-15'),
(1, '2018-01-15');
with cte as (
    select *,
           -- assign row number for each partition consisting of same date
           row_number() over (partition by dt order by dt) as cnt
    from @t
)
-- we're interested only in one row (i.e. first)
select id, dt from cte where cnt = 1;

/*
 Output:
+-------+---------+
| id | dt         |
+----+------------+
|  1 | 2018-01-14 |
|----|------------|
|  1 | 2018-01-15 |
+----+------------+
*/

如果这是您需要的,那么就使用它。@GordonLinoff我不确定这是删除特定列上重复项的正确方式,我想知道最有效的方式。如果您需要删除重复项,您需要在这些日期使用
ROW\u NUMBER()
。@JohnyL您能提供一个例子作为答案吗?我已经回答了