Sie sind auf Seite 1von 2

--Write an Oracle SQL Query to find how many products are delivered out of delivery

date.

SELECT COUNT(A.ORDER_ID) AS DELAYED_DELIVERY


FROM ORDERS A
JOIN DELIVER B
ON A.ORDER_ID = B.ORDER_ID
WHERE A.EXPECTED_DATE > B.ACTUAL_DATE
--Write an Oracle SQL Query to find out what is the most preferred payment method
for customer?
SELECT PAYMENT_MODE,COUNT(PAYMENT_MODE) AS PREFERD
FROM ORDERS
GROUP BY 1
ORDER BY 2 DESC;
--Write an Oracle SQL Query to find out what is the most preferred payment method
for customer?
SELECT PAYMENT_MODE
FROM ORDERS
GROUP BY 1
QUALIFY (ROW_NUMBER() OVER(ORDER BY COUNT(PAYMENT_MODE) DESC))=1
--Write an Oracle SQL Query to find least selling product
SELECT C.PRODUCT_ID,SUM(C.SELLING_PRICE) AS TOTAL_SALE
FROM
(SELECT B.PRODUCT_ID,B.PRODUCT_NAME,(A.QUANTITY*B.PRICE) AS SELLING_PRICE
FROM ORDERS A
JOIN PRODUCT B
ON A.PRODUCT_ID = B.PRODUCT_ID) C
GROUP BY 1
QUALIFY (RANK() OVER ( ORDER BY TOTAL_SALE ASC)) = 1
--Write an Oracle SQL Query to find least selling product
SELECT B.PRODUCT_ID,B.PRODUCT_NAME,SUM((A.QUANTITY*B.PRICE)) AS SELLING_PRICE
FROM ORDERS A
JOIN PRODUCT B
ON A.PRODUCT_ID = B.PRODUCT_ID
GROUP BY 1,2
QUALIFY (RANK() OVER (ORDER BY SELLING_PRICE ASC))=1
--Write an Oracle SQL Query to find total sales day wise for the month of July 2016
SELECT EXTRACT(DAY FROM A.ORDER_DATE) AS DAILY,SUM((A.QUANTITY*B.PRICE)) AS
DAILY_SALE
FROM ORDERS A
JOIN PRODUCT B
ON A.PRODUCT_ID = B.PRODUCT_ID
WHERE (EXTRACT(YEAR FROM ORDER_DATE) = '2016') AND (EXTRACT(MONTH FROM
ORDER_DATE)='7')
GROUP BY 1;
--Write an Oracle SQL Query to find top 5 selling product in the last month
SELECT EXTRACT(DAY FROM A.ORDER_DATE) AS DAILY,SUM((A.QUANTITY*B.PRICE)) AS
DAILY_SALE
FROM ORDERS A
JOIN PRODUCT B
ON A.PRODUCT_ID = B.PRODUCT_ID
WHERE (EXTRACT(YEAR FROM ORDER_DATE) = '2016')
AND
(EXTRACT(MONTH FROM(ADD_MONTHS(TRUNC(ORDER_DATE,'MON'),-1))) = '6')
((ADD_MONTHS(TRUNC(EXTRACT(MONTH FROM ORDER_DATE)),'MON'),-1)=6)
GROUP BY 1;
QUALIFY (RANK() OVER(ORDER BY DAILY_SALE) IN (1,2,3,4,5));
--Write an Oracle SQL Query to find highest selling product on a particular day
SELECT B.PRODUCT_NAME,SUM((A.QUANTITY*B.PRICE)) AS DAILY_SALE
FROM ORDERS A
JOIN PRODUCT B
ON A.PRODUCT_ID = B.PRODUCT_ID
GROUP BY EXTRACT(DAY FROM A.ORDER_DATE),1
QUALIFY (RANK() OVER(ORDER BY DAILY_SALE DESC) = 1)