经典sql语句

来源:互联网 发布:ubuntu最新版本是多少 编辑:程序博客网 时间:2024/04/29 07:27

create table tablename(
序号 int ,
姓名 varchar(80),
日期 varchar(50)
)

go

insert tablename select 1,'张三','20051102'
union select 2,'张三','20051104'
union select 3,'张三','20051105'
union select 4,'张三','20051107'
union select 5,'李四','20051102'
union select 6,'李四','20051111'
union select 7,'王五','20051116'
union select 8,'王五','20051109'
union select 9,'张三','20051122'

go
---查询
select * from tablename
 where 序号 in(
   select 序号 from tablename a
      where not exists(
         select * from tablename b
            where b.序号=a.序号-1 and b.姓名=a.姓名
        ))

drop table tablename

原创粉丝点击