用户编号 姓名      角色            模块代码   模块名称
0000 A 系统管理员 01 生产管理
0000 A 系统管理员 02 库存管理
0000 A 系统管理员 03 采购管理
0000 A 系统管理员 04 销售管理
0000 A 系统管理员 05 系统管理
0000 A 操作员     05 系统管理如何在用select查询的时候把最后两条重复的,去掉一条,  最后两条角色虽然不同,但 模块相同

解决方案 »

  1.   

    select * from tablename where 模块名称 in(select distinct 模块名称 from tablename)
      

  2.   

    SELECT DISTINCT *
    FROM tables
      

  3.   

    select m.* from tb m,
    (select 模块名称,max(角色) from tb group by 模块名称) n
    where m.模块名称=n.模块名称 and m.角色 = n.角色max那个地方用min也行.
      

  4.   


    select max(用户编号) as 用户编号,
    max(姓名) as 姓名,
    max(角色) as 角色,
    max(模块代码) as 模块代码,
    模块名称
    from tbName group by 模块名称
      

  5.   

    create table T(用户编号 char(4), 姓名 char(1),      角色 nvarchar(10),           模块代码 char(2),   模块名称 nvarchar(10))
    insert T select '0000', 'A', '系统管理员', '01', '生产管理'
    union all select '0000', 'A', '系统管理员', '02', '库存管理'
    union all select '0000', 'A', '系统管理员', '03', '采购管理'
    union all select '0000', 'A', '系统管理员', '04', '销售管理'
    union all select '0000', 'A', '系统管理员', '05', '系统管理'
    union all select '0000', 'A', '操作员',     '05', '系统管理'select max(用户编号) as 用户编号,
    max(姓名) as 姓名,
    max(角色) as 角色,
    max(模块代码) as 模块代码,
    模块名称
    from T group by 模块名称
    order by 模块代码--result
    用户编号 姓名   角色         模块代码 模块名称       
    ---- ---- ---------- ---- ---------- 
    0000 A    系统管理员      01   生产管理
    0000 A    系统管理员      02   库存管理
    0000 A    系统管理员      03   采购管理
    0000 A    系统管理员      04   销售管理
    0000 A    系统管理员      05   系统管理(5 row(s) affected)