6

我有一个表,其中包含以下值的调用者和被调用者列

caller callee
999 888
888 999
999 555
555 333
555 999

现在我只想返回单行

caller1    caller2  count 
999        888      2
999        555      1
555        333      1
555        999      2
4

1 回答 1

6
SELECT CASE
         WHEN caller < callee THEN callee
         ELSE caller
       END      AS caller1,
       CASE
         WHEN caller < callee THEN caller
         ELSE callee
       END      AS caller2,
       Count(*) AS [Count]
FROM   YourTable
GROUP  BY CASE
            WHEN caller < callee THEN callee
            ELSE caller
          END,
          CASE
            WHEN caller < callee THEN caller
            ELSE callee
          END 
于 2012-10-12T13:08:20.383 回答