请教一下各位:
 表如下:
id       userid   funtionName
1 1 药物专论
2 2 配伍挤
4 3 时讯
5 1 时讯
6 2 药物的相互作用
7 2 药物专论
8 3 配伍挤
问:
要显示这三列 但是funtionName不能有重复
sql语句怎么写
????

解决方案 »

  1.   

    按说除了id(自增)无重复外,其余都允许有重复的,包括functionName也不应除外
      

  2.   

    SELECT DISTINCT funtionName FROM  tb
      

  3.   

    sql: 
    ... order by functionName
      

  4.   

    SELECT DISTINCT id, userid, funtionName, FROM TABLE
      

  5.   

    SELECT DISTINCT id, userid, funtionName, FROM TABLE
      

  6.   

    对id userid 这两列有要求吗?没有的话可以这样:
    slect max(id),max(userid),funtionName
    from table 
    group by funtionName
      

  7.   

    sql 拼接字符串
    http://topic.csdn.net/u/20100412/22/fec647ea-73d0-480b-92e9-8af61ef3c978.html
      

  8.   


    --不重复的记录有
    select id,userid,funtionname from tablename --where 
    group by id,userid,funtionname
    having count(funtionname)=1
    --重复的记录
    select id,userid,funtionname from tablename --where 
    group by id,userid,funtionname
    having count(funtionname)>1
      

  9.   

    SELECT DISTINCT id, userid, funtionName FROM TABLE
      

  10.   

    刚好上午写了一个
    --> 数据库版本:
    --> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
    --> 测试数据:[TB]
    IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]') 
    AND type in (N'U')) 
    DROP TABLE [TB]
    GO---->建表
    create table [TB]([id] int,[userid] int,[funtionName] varchar(14))
    insert [TB]
    select 1,1,'药物专论' union all
    select 2,2,'配伍挤' union all
    select 4,3,'时讯' union all
    select 5,1,'时讯' union all
    select 6,2,'药物的相互作用' union all
    select 7,2,'药物专论' union all
    select 8,3,'配伍挤'
    GO
    --> 查询结果
    alter table TB add dd varchar(20)
    godeclare @i int,@fff varchar(20)=''
    set @i=1
    update [TB]
    set dd=@i, @i=case when [funtionName]!=@fff then 0  else @i+1 end ,@fff=[funtionName]
    goSELECT * FROM [TB] 
    where dd=0alter table TB drop column dd
    --> 删除表格
    --DROP TABLE [TB]
      

  11.   

    要显示这三列 但是funtionName不能有重复id 是不重复的,显示还有什么意义。即使去掉funtionName重复的,id也是缺失的。
      

  12.   

    SELECT MAX(id) AS id, MAX(userid) AS userid, funtionName FROM t GROUP BY funtionName
    这样就可以了,简单的很,其它楼主你应该表明,是funtionName重要,还是UserID重要,按我的理解,是funtionName重要,至于相同的funtionName取什么UserID,楼主有什么要求吗?
    上面的语句是,相同的funtionName取UserID大的记录
      

  13.   

    SELECT MAX(id) AS id, MAX(userid) AS userid, funtionName FROM t GROUP BY funtionName
      

  14.   


    select * from table 
    where id in (select min(id) from table group by funtionName)
      

  15.   


    要显示3列,用 group / distinct 都没用,因为 id 是不会重复的所以只能先对 funtionName group
    其他2个字段只能用表达式了
      

  16.   

    DISTINCT的使用有局限,不能完全解决楼主的问题
    参见一篇MySql的贴子应该有借鉴作用:
    查询不重复记录
      

  17.   

    select id,userid,funtionname from tablename --where 
    group by id,userid,funtionname
    having count(funtionname)=1
      

  18.   


    count(funtionname)=2 的显示否?
      

  19.   

    直接对funtionName group by就行了
    select id,userid,funtionName from 表 group by funtionName