Harish Prasad
Harish Prasad

Reputation: 37

Oracle SQL query to pivot like excel

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?

Upvotes: 3

Views: 16068

Answers (1)

CompEng
CompEng

Reputation: 7376

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')
) ;

Upvotes: 4

Related Questions