读书人

关于sql 数据清理的有关问题

发布时间: 2012-09-06 10:37:01 作者: rapoo

关于sql 数据清理的问题
现在假设有一张学生住宿信息表,sql字段有 id(不是学号),房号,上次时间,本次时间,住宿名单1,住宿名单2,住宿名单3,住宿名单4, 要怎么通过这些字段找出是否有同名的学生。

[解决办法]

SQL code
with cte as (select *, row_number() over( order by getdate()) as id from (select 住宿名单1 as col from tbunion allselect 住宿名单2 from tbunion allselect 住宿名单3 from tbunion allselect 住宿名单4 from tb) as t )select * from cte as a where exists (   select * from cte as b       where a.col = b.col and             a.id <> b.id) 

读书人网 >SQL Server

热点推荐