SQL Test - Analyst
SQL Test - Analyst
transactions
PART 1
From the table above, write the SQL query to (preferably using MySQL syntax, but you can also
use SQL Server, Redshift SQL or ANSI standard syntax):
1. Show list of transactions occurring in February 2018 with SHIPPED status.
2. Show list of transactions occurring from midnight to 9 AM
3. Show a list of only the last transactions from each vendor
4. Show a list of only the second last transactions from each vendor
5. Count the transactions from each vendor with the status CANCELLED per day
6. Show a list of customers who made more than 1 SHIPPED purchases
7. Show the total transactions (volume) and category of each vendors by following these criteria:
a. Superb: More than 2 SHIPPED and 0 CANCELLED transactions
b. Good: More than 2 SHIPPED and 1 or more CANCELLED transactions
c. Normal: other than Superb and Good criteria
Order the vendors by the best category (Superb, Good, Normal), then by the biggest
transaction volume
Vendor Category Total Transaction
Vendor D Superb 3
00 3
03 1
05 1
... ...
2018-01-01 2 0 0
2018-01-02 0 1 0
2018-02-04 0 1 0
... ...
10. Calculate the average, minimum and maximum of days interval of each transaction (how
many days from one transaction to the next)
2 1 Taro 80 5500
4 2 Taro 41 5500
16 7 Coki-coki 70 1000
The new table, “transaction_details” contains the details of purchased item of each transaction in
“transactions” table.
PART 2
In reference to both tables, write an SQL query to:
1. Show the sum of the total value of the products shipped along with the Distributor
Commissions (2% of the total product value if total quantity is 100 or less, 4% of the total
product value if total quantity sold is more than 100)
2. Show total quantity of “Indomie (all variant)” shipped within February 2018
total_quantity
xxx
3. For each product, show the ID of the last transaction which contained that particular product
Beng beng 4
Coki-Coki 7
… …