Answer the question
In order to leave comments, you need to log in
How to calculate the discount?
Hello. There are 3 tables - Discounts (Discount), Clients (Clients) and Orders (Orders)
Discount
id_discount count_orders percent_discount
1 5 1,5
2 10 2,5
id_client Name Surname
1 Ivan Petrov
2 Vasya Vasev
id order_sum
Answer the question
In order to leave comments, you need to log in
You need to add a secondary key to the Orders table to link to the Clients table. those. add clients_id field. And then, through the inner join, contact the Discount table and calculate the total discount.
in Orders we add id_client
count_orders we do as an interval from 5 to 10 and from 10 to 100000000000000 for example, because otherwise it will be problematic to manage without functions and additional selections
select
Discount.percent_discount
from
Discount
where
(select count(Orders.id_client) where id_client = ...) BETWEEN Discount.count_orders_min AND Discount.count_orders_max
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question