SQL - Oracle
Peckers
Sweden
The query I'm trying to construct: What's the least popular product(s)?
First Select will return the furnitureno of furniture(s) that have never been ordered.
Second Select will return the furnitureno of the furniture(s) with the least number of orders.
This all works fine, but I only want the second Select to run if there is no furnitures with no(NULL) orders.
Any ideas?
SELECT FURNITURENAME, FURNITURENO, 'NO ORDERS' AS STATUS FROM MY_FURNITURE WHERE FURNITURENO NOT IN (SELECT FURNITURENO FROM MY_FURNITUREORDER) UNION SELECT FURNITURENAME, FURNITURENO, 'LEAST ORDERED' AS STATUS FROM MY_FURNITURE WHERE FURNITURENO IN (SELECT FURNITURENO FROM MY_FURNITUREORDER GROUP BY FURNITURENO HAVING COUNT(FURNITURENO) = (SELECT MIN(COUNT(FURNITURENO)) FROM MY_FURNITUREORDER GROUP BY FURNITURENO)) ORDER BY FURNITURENO;
First Select will return the furnitureno of furniture(s) that have never been ordered.
Second Select will return the furnitureno of the furniture(s) with the least number of orders.
This all works fine, but I only want the second Select to run if there is no furnitures with no(NULL) orders.
Any ideas?
0
Comments
I'll have a look at CASE, that might work.