views:

122

answers:

1

Am trying to write a query that would output something similar to the last batch of records below. For sure it works in Reporting Services and Crystal Reports, but just throwing it out here to see if it is possible in SSMS/QA:

Table:
id name amount
-- ---- ------
 1 rob   23.00
 2 rob   34.00
 3 dan   45.00
 4 dan   56.00

select name, amount from t1 
Query resulting in:
name amount
---- ------
rob   23.00
rob   34.00
dan   45.00
dan   56.00

DESIRED result:
name amount
---- ------
rob   23.00
      34.00
dan   45.00
      56.00

Thanks!

+3  A: 

Try this:

SELECT CASE WHEN _rank = 1 THEN name ELSE '' END AS name, amount
FROM (
    SELECT name, amount,
     ROW_NUMBER() OVER (PARTITION BY name ORDER BY amount ASC) AS _rank
    FROM t1
) q
eKek0
Exactly what I'm looking for. Thanks Ekeko!
rob
you have to mark a question as accepted. I guess you don't know that because you are new here.
eKek0
yeah, was looking for 'Accept' earlier... then had to read some FAQs, bingo!
rob