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

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

2012-09-06 
关于sql 数据清理的问题现在假设有一张学生住宿信息表,sql字段有 id(不是学号),房号,上次时间,本次时间,住

关于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) 

热点排行