Toad World® Forums

Help with Lines to columns

HI there, since I’m new at SQL language and have learned it on the job since April I need a little help.

I have a query that provides me with me a list of calls on customers.

I have a date range for the call counts I want to extract.

My current query returns as many lines per customers as we have products and this is my problem.

What I would look for is to have a single line per customer and every product’s YTD calls in column format with basically as many columns as we have products.

If an existing customer was not seen for any prod, I would still expect the customer to be displayed with zero calls for each Product column.

P.External_id_1 are the products.

This is the query I’m using:

select to_char (c.customer_id), count(e.event_id), p.external_id_1 as PRODUCT from

wfprod.event e inner join

WFPROD.EVENT_detail ed on e.event_id = ed.event_id inner join

wfprod.product p on p.product_id = ED.PRODUCT_ID inner join

wfprod.customer c on C.CUSTOMER_ID = e.customer_id

where e.start_date_time >=to_date(‘2014-04-01’, ‘YYYY-MM-DD’) and e.start_date_time <=to_date(‘2015-04-01’, ‘YYYY-MM-DD’)

group by c.customer_id, p.external_id_1;

Sorry, this is not a discussion, but a question…