哥们,你的a1,a2是结果还是column。详细些。

解决方案 »

  1.   

    是这个意思吗?
    select a=a1+','+a2+','+a3,b from t group by a1+','+a2+','+a3,b
      

  2.   

    我以前做排序是这样做的:SELECT a.nYear,a.strAreaID,a.nMainBussinessID, a.strMainBussinessName, 
          CASE WHEN a.fScore IS NULL THEN NULL 
          ELSE COUNT(b.fScore) + 1 END AS nPlace, 
          a.fScore_All,a.fScore, 
          a.fScoreLost,a.fScoreRatio, 
          a.fScoreLostRatio
    FROM dbo.vScore_Year_Type a LEFT OUTER JOIN
          dbo.vScore_Year_Type b ON 
          a.nYear =b.nYear AND 
          a.nMainBussinessID =b.nMainBussinessID
           AND a.fScore < b.fScore
    GROUP BY a.strAreaID,a.nYear, 
          a.nMainBussinessID, 
          a.strMainBussinessName,a.fScore_All, 
          a.fScore,a.fScoreLost, 
          a.fScoreRatio,a.fScoreLostRatio
    ORDER BY a.nYear,a.nMainBussinessID, 
          CASE WHEN a.fScore IS NULL THEN NULL 
          ELSE COUNT(b.fScore) + 1 END但现在对字符串进行处理,不知怎么办了?
      

  3.   

    to  zjcxc(邹建) ( ) ,你理解错了.是a1,a2,a3.....是分组前对应a组中几项.表达能力有限,我举了一个我排序的例子,不知能不能说清楚,请见谅!
      

  4.   

    select max(a1+','+a2+','+a3),b from t group by a,b select min(a1+','+a2+','+a3),b from t group by a,b 取个聚集函数就不会有语法错误
      

  5.   

    是这个意思吗?
    SELECT * 
    FROM (SELECT a1 + ',' + a2 + ',' + a3 as a ,b FROM t) as table1
    GROUP BY table1.a , table1.b
      

  6.   

    是这个意思吗?
    SELECT * 
    FROM (SELECT a1 + ',' + a2 + ',' + a3 as a ,b FROM t) as table1
    GROUP BY table1.a , table1.b
      

  7.   

    ALTER PROCEDURE dbo.testt
    @res varchar (1024) output
    as-- Declare the variables to store the values returned by FETCH.
    DECLARE @a varchar(40)
    DECLARE test_cursor CURSOR FOR
    SELECT a FROM test
    group by a,b
    OPEN test_cursor-- Perform the first fetch and store the values in variables.
    -- Note: The variables are in the same order as the columns
    -- in the SELECT statement. FETCH NEXT FROM test_cursor
    INTO @a-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
    WHILE @@FETCH_STATUS = 0
    BEGIN   -- Concatenate and display the current values in the variables.
       --PRINT "Author: " + @au_fname + " " +  @au_lname
       set @res = @res + rtrim(@a) + ','
       -- This is executed as long as the previous fetch succeeds.
       FETCH NEXT FROM test_cursor
       INTO @a
    END
    print @resCLOSE test_cursor
    DEALLOCATE test_cursorreturn
      

  8.   

    谢谢大件和yohomonkey(关在笼子里的猴).