select name,group_concat(num) as num from table where name='red' group by 1;

解决方案 »

  1.   

    select top 1 a.name,a.num+','+b.num as gnum from #table a join #table b on a.id=b.id where a.name='red' and a.num <> b.num
      

  2.   

    猩猩就是猩猩哈,就是比我这个裤衩厉害,group_concat(),这个没想到,佩服~~学习~~~~
    Aylazhang(春暖花开) 这几天总遇上,这次也麻烦你了,不过你的sql我没看明白,能大体解释一下吗,我只有一个table啊,怎么弄出的table a 和 table b
      

  3.   

    我也来凑个人数吧select   name,group_concat(num)   as   num   
    from   table   
    where   name= "red "   
    group   by   1;
    ==============================================
    学习一下你的代码哈
      

  4.   

    我的是mssql的写法,比较简单。
      

  5.   

    to Aylazhang : 这条SQL语句好像只是针对
    name             num 
    red               1001,1003 的。
    那如果有3个、4个人的name都是red,
    select   top   1   a.name,a.num+ ", "+b.num   as   gnum   from   #table   a   join   #table   b   on   a.id=b.id   where   a.name= "red "   and   a.num   < >   b.num
    这条SQL语句好像就不行了吧?
      

  6.   

    对头,作用很有限。所以还是考虑group_concat()之类的函数。
      

  7.   

    select   name,group_concat(num)   as   num   from   table   group   by   name;
      

  8.   

    其实是这样的,我是帮朋友问的,group_concat是mysql独有的,我朋友的数据库是oracle,我以为sql标准都一样,所以就没说明,结果给了朋友才发现oracle不支持group_concat,不过我已经没脸面再要求大家什么了,group_concat以前我还真就不知道,这次也算有收获了,谢谢大家帮忙~~~~
      

  9.   

    你可以在 csdn搜索下,有oracle函数实现这个功能的。
    或者有个function实现,里面用游标就可以了,这个比较简单的