I have below query where i am trying to achieve using pivot. Is there any way i can define a sub query inside IN clause in pivot. I tried PIVOT XML but i am not getting expected output
SELECT * FROM
(
SELECT customer_ref, product_id
FROM orders
)
PIVOT
(
COUNT(product_id)
FOR product_id IN (10, 20, 30)
)
ORDER BY customer_ref;
how can i define a sub query in the IN clause
is there any possibility for ---FOR product_id IN (select distinct product_id from orders).
I tried PIVOT XML but it was displaying xml code which is not expected output.
Is there any way to achieve ?