本帖最后由 jzkaixin 于 2012-11-27 08:34:47 编辑

解决方案 »

  1.   

    先根据班级升序排列 order by class 
    再去重前提是 你一个班里不会出现两个 相同姓名 年龄 性别的人
      

  2.   

    不太懂楼主的意思,难道是要下面的结果? 但是这个结果个人觉得没什么意义--测试数据
    if OBJECT_ID('student') is not null drop table student
    create table student(ID int identity(1,1),姓名 nvarchar(20),性别 int,年龄 int,班级 int)
    go
    insert into student(姓名,性别,年龄,班级)
    select '张三',1,18,1 union all
    select '李四',1,18,1 union all
    select '赵武',1,19,1 union all
    select '小明',1,17,1 union all
    select '刘涛',1,18,2 union all
    select '小红',2,17,2 union all
    select '小芳',2,18,2 union all
    select '小红',2,18,2 union all
    select '张三',1,18,1 union all
    select '李四',1,17,1
    --查询
    select 姓名,性别,年龄 From student GROUP BY 班级,姓名,性别,年龄
    union all
    select 姓名,性别,年龄 From student GROUP BY 班级,姓名,性别,年龄 having COUNT(1)>1/**
    姓名                   性别          年龄
    -------------------- ----------- -----------
    李四                   1           17
    李四                   1           18
    小明                   1           17
    张三                   1           18
    赵武                   1           19
    刘涛                   1           18
    小芳                   2           18
    小红                   2           17
    小红                   2           18
    张三                   1           18(10 行受影响)
    **/
      

  3.   


    ----------------------------------------------------------------
    -- Author  :TravyLee(物是人非事事休,欲语泪先流!)
    -- Date    :2012-11-27 12:19:06
    -- Version:
    --      Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86) 
    -- Jul  9 2008 14:43:34 
    -- Copyright (c) 1988-2008 Microsoft Corporation
    -- Developer Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
    --
    ----------------------------------------------------------------
    --> 测试数据:[test]
    if object_id('[test]') is not null 
    drop table [test]
    go 
    create table [test]
    (
    [ID] int,
    [姓名] varchar(4),
    [性别] int,
    [年龄] int,
    [班级] int
    )
    insert [test]
    select 1,'张三',1,18,1 union all
    select 2,'李四',1,18,1 union all
    select 3,'赵武',1,19,1 union all
    select 4,'小明',1,17,1 union all
    select 5,'刘涛',1,18,2 union all
    select 6,'小红',2,17,2 union all
    select 7,'小芳',2,18,2 union all
    select 8,'小红',2,18,2 union all
    select 9,'张三',1,18,1 union all
    select 10,'李四',1,17,1
    goselect
    *
    from
    test a
    where
    a.ID=(
    select
    min(ID)
    from
    test b
    where
    a.姓名=b.姓名 
    and a.性别=b.性别
    and a.年龄=b.年龄
     )
    order by
    id
    /*
    ID          姓名   性别          年龄          班级
    ----------- ---- ----------- ----------- -----------
    1           张三   1           18          1
    2           李四   1           18          1
    3           赵武   1           19          1
    4           小明   1           17          1
    5           刘涛   1           18          2
    6           小红   2           17          2
    7           小芳   2           18          2
    8           小红   2           18          2
    10          李四   1           17          1(9 行受影响)
    */--按照你的意思就是这个结果  但是估计你不是这个意思  给出你期待的结果
      

  4.   

    select *,ROW_NUMBER() over(partition by [班级] order by [姓名]) AS 分组 from test