Reputation: 4963
I have a table with columns caller and callee with following values say
caller callee
999 888
888 999
999 555
555 333
555 999
now i want only single row in returned as
caller1 caller2 count
999 888 2
999 555 1
555 333 1
555 999 2
Upvotes: 6
Views: 610
Reputation: 452978
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
Upvotes: 6