SQL Test
SQL Test
SQL Test
Question: Please write a query script in SQL for each of the following tasks.
1.) Sum of sales of 'Thailand' and 'Philipines' country in June 2017, considering only order with 'DELIVERED' status
2.) Top 10 best selling item based on number of unit solds (quantity) for partner_name XYZ
3.) Distinct count of customer who has 'REJECTED' order that has '1001' as item_id in February and March 2017
4.) Number of order in each province and percentage comparing to total number of order
5.) Commission fee for each order from partner XYZ which calculated from total selling price
Result example: partner_name order_id order_date Commission rate total_selling_price Commission fee
XYZ A0001 1-Jan-17 2% 100 2
XYZ A0002 11-Jan-17 2% 20 0.4
XYZ A0002 11-Jan-17 2% 120 2.4
XYZ A0002 11-Jan-17 2% 200 4
XYZ A0005 15-Apr-17 5% 100 5
7.) List of orders that are delivered to the invalid location (postcode that cannot be identified its provice)
8.) Top 1 best selling item based on number of unit solds (quantity) for every partner
1 3
SALES_ORDER PARTNER
order_id partner_id
partner_id partner_name
item_id country
item_quantity
total_selling_price
sales_channel partner_id partner_name country
order_date 1 XYZ Thailand
customer_id 2 QWE Singapore
3 DFG Philipines
order_id partner_id item_id item_quantity total_selling_price sales_channel order_date customer_id
2 5
ORDER_STATUS Area
order_id postal_code
partner_id province
status
delivered_date
destination_postal code postalcode province
10600 กรุงเทพฯ
40560 ยะลา
10500 กรุงเทพฯ
55012 สงขลา
order_id partner_id status delivered_datedestination_postal code 40620 น่าน
A0001 1 REJECTED 1-Jan-17 10600 10800 กรุงเทพฯ
A0002 1 DELIVERED 11-Jan-17 40560 59850 ประจวบ
A0003 2 DELIVERED 3-Mar-17 10500
A0005 1 DELIVERED 15-Apr-17 10800
A0006 2 DELIVERED 1-Jun-17 40620
A0007 3 IN_TRANSIT ppp