当前位置: 代码迷 >> Sql Server >> 关于sql 数据清理的有关问题
  详细解决方案

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

热度:75   发布时间:2016-04-27 11:47:19.0
关于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)
  相关解决方案