Найти какие тарифы доступны каким клиентам
SELECT
id AS clientId,
clients.id AS tariffId,
prices.AS tariffName
prices.name FROM
((pricesJOIN tariffs ON ((prices.id = tariffs.idPrice)))
JOIN clients ON ((tariffs.isMember = clients.isMember)))
Выбрать резервы клиента
select startTime, courtNo, duration from reservesView where idClient=id;
Выбрать все резервы с именем клиента
SELECT
AS idClient,
reserves.idClient AS clientName,
clients.name AS startTime,
reserves.startTime AS courtNo,
reserves.idCourt AS duration
reserves.duration FROM
(reservesJOIN clients ON ((reserves.idClient = clients.id)))
и ценой резерва
SELECT
AS idClient,
reserves.idClient AS clientName,
clients.name AS startTime,
reserves.startTime AS courtNo,
reserves.idCourt AS duration,
reserves.duration AS pricePerHour,
prices.price *TIME_TO_SEC(duration)/3600 AS totalPrice
prices.priceFROM
reservesJOIN clients ON reserves.idClient = clients.id
JOIN tariffs ON reserves.idCourt = tariffs.idCourt AND clients.isMember = tariffs.isMember
JOIN prices ON tariffs.idPrice = prices.id;
Приход от клиентов в текущем месяце
SELECT
AS idClient,
reserves.idClient AS name,
clients.name SUM(prices.price*TIME_TO_SEC(duration)/3600) AS income
FROM
reservesJOIN clients ON clients.id = reserves.idClient
JOIN tariffs ON clients.isMember = tariffs.isMember
AND reserves.idCourt = tariffs.idCourt
JOIN prices ON tariffs.idPrice = prices.id
WHERE MONTH(startTime) = MONTH(NOW())
GROUP BY reserves.idClient;