0

I have table data such as this

index  user  date   rank
  11     a    1Mar    23
  12     b    1Mar    16
  13     a    2Mar    24
  14     b    2Mar    18

What I would like to achieve via a query is this:

    1Mar   2Mar
a   23     24
b   16     18 

I don't know if this can be done via a single statement at the command line or if this will have to be done via a form and some scripting. Doing through scripting I can do, but can't see how to do in a single statement.

1
  • It can be done in a single statement. Commented Oct 20, 2014 at 3:41

1 Answer 1

1

you can do pivot like below, if you know all possible values for date or you need to use dynamic sql.

SELECT user,
       MAX( CASE WHEN date ='1Mar' THEN rank else NULL end) AS '1Mar',
       MAX( CASE WHEN date ='2Mar' THEN rank else NULL end) AS '2Mar'
FROM Table1
GROUP BY user
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.