2023-01-15
Max. 50 points
Name:
Task | Max. | Achieved |
---|---|---|
1 | 4 | |
2 | 4 | |
3 | 10 | |
4 | 14 | |
5 | 18 | |
Sum | 50 |
To solve the tasks in this test, use the following ERD and data tables.
customers | ||||
---|---|---|---|---|
customer_id | first_name | last_name | iban | country |
1 | Per | Kronberg | SE12 7463 1923 9451 2942 | Sweden |
2 | Leonie | Yvroud | FR94 2874 8475 1238 4845 | France |
3 | Derrek | Sonnamaker | AT32 0000 0012 3941 3944 | USA |
employees | |||||
---|---|---|---|---|---|
employee_id | first_name | last_name | salary | commission_rate | |
1 | Chris | Sanders | 70,000 | 3 | |
2 | Pat | Steward | 55,000 | 5 | |
3 | Sue | Hedborg | 61,000 | 4 | |
4 | Francois | Dupois | 65,000 | 3 | |
5 | Cat | Whitherspoon | 75,000 | 2.5 |
orders | ||||
---|---|---|---|---|
order_id | filed | gross_price | customer_id | employee_id |
1 | 2023-01-01 | 35,000 | 3 | 5 |
2 | 2023-01-01 | 8,500 | 2 | 4 |
3 | 2023-01-02 | 15,000 | 3 | 5 |
4 | 2023-01-03 | 6,800 | 1 | 2 |
Statement | True | False |
---|---|---|
select count(*) from orders yields 5. | ||
select count(*) from orders cross join
employees yields 20. | ||
"select * from employees
natural join orders;" and "select * from employees
join orders using (employee_id);" have the same result. | ||
In MariaDB, aggregate functions cannot be used
without group by . |
select * from employees e
natural join orders o;
select o.order_id, o.filed, o.gross_price,
concat(e.first_name, ' ', e.last_name) as Employee,
concat(c.first_name, ' ', c.last_name) as Customer
from employees e
natural join orders o
right outer join customers c using (customer_id);
-- mariadb solution
select filed as 'Filed', sum(gross_price) as Total from orders o
where o.filed >= "2023-01-01"
group by filed
order by filed;
select c.first_name, c.last_name, sum(o.gross_price) as "Sum"
from customers c
natural join orders o
group by c.customer_id
order by sum(o.gross_price) desc;
select e.last_name , sum(o.gross_price * e.commission_rate / 100) as commission
from employees e
natural join orders o
where o.filed BETWEEN "2023-01-01" and "2023-01-31"
group by e.employee_id
order by e.last_name