Your Customer phone directory table allows individuals to setup a home, cellular, or a work phone number.
Write a SQL statement to transform the table into the expected output.
Your Customer phone directory table allows individuals to setup a home, cellular, or a work phone number.
Write a SQL statement to transform the table into the expected output.
Write an SQL statement given the following requirements.
For every customer that had a delivery to Hyderabad, provide a result set of the customer orders that were delivered to Bangalore.
WITH CUSTOMER_ORDER AS (
SELECT 1001 CUSTOMER_ID,'Ord1234' ORDERID,'HYDERABAD' DELIVERY_CITY,100 AMOUNT FROM DUAL
UNION
SELECT 1001 CUSTOMER_ID,'Ord1235' ORDERID,'BANGALORE' DELIVERY_CITY,123 AMOUNT FROM DUAL
UNION
SELECT 1001 CUSTOMER_ID,'Ord1236' ORDERID,'HYDERABAD' DELIVERY_CITY,341 AMOUNT FROM DUAL
UNION
SELECT 2001 CUSTOMER_ID,'Ord1237' ORDERID,'HYDERABAD' DELIVERY_CITY,890 AMOUNT FROM DUAL
UNION
SELECT 2001 CUSTOMER_ID,'Ord1238' ORDERID,'BANGALORE' DELIVERY_CITY,44 AMOUNT FROM DUAL
UNION
SELECT 3001 CUSTOMER_ID,'Ord1244' ORDERID,'HYDERABAD' DELIVERY_CITY,99 AMOUNT FROM DUAL
UNION
SELECT 4001 CUSTOMER_ID,'Ord1245' ORDERID,'HYDERABAD' DELIVERY_CITY,1020 AMOUNT FROM DUAL
UNION
SELECT 4001 CUSTOMER_ID,'Ord1246' ORDERID,'CHENNAI' DELIVERY_CITY,234 AMOUNT FROM DUAL
)
SELECT *
FROM customer_order o
WHERE
2 = (
SELECT count(distinct delivery_city)
FROM customer_order i
WHERE
delivery_city IN (
'HYDERABAD',
'BANGALORE'
)
AND o.customer_id = i.customer_id
)
ORDER BY
1;
Managers and Employees:
Given the following table, write a SQL statement that determines level of depth each employee has from the president
Source Table:
Script:
SELECT
employee_id,
manager_id,
job_id,
salary,
level - 1 depth
FROM
hr.employees
START WITH
manager_id IS NULL
CONNECT BY
PRIOR employee_id = manager_id
order by 1;
1. Picking Dance Partners
Pick the dance partners from the following table:
Note: There is mismatch in the number of students, as one male student will be left without a dance partner. Please include this individual in your list as well.
Expected Output:
SQL Query:
Input:
Input:
UNPIVOT_TABLE Data:
SELECT * FROM
(SELECT *
FROM UNPIVOT_TABLE)
PIVOT (MAX(SALES) FOR QUARTER IN ('Q1' AS Q1,'Q2' AS Q2,'Q3' AS Q3,'Q4' AS Q4));
Input:
Expected Output:
Query:
PIVOT_TABLE Data:
SELECT * FROM
(SELECT *
FROM PIVOT_TABLE)
UNPIVOT(SALES FOR QUARTER IN (Q1, Q2, Q3, Q4));