4

I would like pivot using sql query below would be my data format:

Date Sales Count
07-May Coffee 20
07-May Tea 50
07-May Chia 30
14-May Tea 40
14-May Coffee 60

I would like my data to be output using oracle sql query to be in the below format:

Sale 07-May 14-May
Coffee 20 60
Chia 30
Tea 50 40

Could you please assist over here?

3

1 Answer 1

8

you can use pivot like this:

SELECT * FROM
(
  SELECT Date,Sales,Count
  FROM your_table
)
PIVOT
(
  sum(Count)
  FOR Date IN ('07-May', '14-May')
) ;
Sign up to request clarification or add additional context in comments.

1 Comment

I would like to pass the date range rather than mentioning individual dates as that would ensure that i am not missing any date.

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.