首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

用sql话语删除重复记录

2012-08-16 
用sql语句删除重复记录ExamplesFor each department in the sample table oe.employees, the following ex

用sql语句删除重复记录
Examples

For each department in the sample table oe.employees, the following example assigns numbers to each row in order of employee's hire date:

SELECT department_id, last_name, employee_id, ROW_NUMBER()   OVER (PARTITION BY department_id ORDER BY employee_id) AS emp_id   FROM employees;


DEPARTMENT_ID LAST_NAME                 EMPLOYEE_ID     EMP_ID
------------- ------------------------- ----------- ----------
           10 Whalen                            200          1
           20 Hartstein                         201          1
           20 Fay                               202          2
           30 Raphaely                          114          1
           30 Khoo                              115          2
           30 Baida                             116          3
           30 Tobias                            117          4
           30 Himuro                            118          5
           30 Colmenares                        119          6
           40 Mavris                            203          1
. . .
          100 Popp                              113          6
          110 Higgins                           205          1
          110 Gietz                             206          2

ROW_NUMBER is a nondeterministic function. However, employee_id is a unique key, so the results of this application of the function are deterministic.



非常不错,值得学习!DELETE FROM EMP E WHERE E.ROWID > (SELECT MIN(X.ROWID) FROM EMP X WHERE X.EMP_NO = E.EMP_NO);

热点排行