SELECT
t1.YEAR,
t1.MONTH,
((t1.REGS - t2.REGS) / t1.REGS) * 100 as DYNAMIC
FROM
(
SELECT
EXTRACT(YEAR FROM created_at) as YEAR,
EXTRACT(MONTH FROM created_at) as MONTH,
COUNT(*) AS REGS
FROM users
GROUP BY EXTRACT(YEAR FROM created_at), EXTRACT(MONTH FROM created_at)
) t1
LEFT JOIN
(
SELECT
EXTRACT(YEAR FROM created_at) as YEAR,
EXTRACT(MONTH FROM created_at) as MONTH,
COUNT(*) AS REGS
FROM users
GROUP BY EXTRACT(YEAR FROM created_at), EXTRACT(MONTH FROM created_at)
) t2 ON t2.YEAR = t1.YEAR
AND t2.MOUNT = (t1.MOUNT) + 1
ORDER BY t1.YEAR,t1.MONTH;
select
user_id,
date,
SUM(CASE WHEN currency = 'USD' THEN amount ELSE 0 END) AS USD,
SUM(CASE WHEN currency = 'EUR' THEN amount ELSE 0 END) AS EUR
FROM Table1 AS
GROUP BY user_id, date
SUM( IF(currency = 'USD', amount, 0) ) AS USD,
SUM( IF(currency = 'EUR', amount, 0) ) AS EUR
SELECT Train.nameTrain, Trip.time as date,
Passanger.firstname, Passanger.lastname, Passanger.birthday,
Price.wagon, Ticket.place, Price.price,
Ticket.departureStation, Ticket.arrivalStation,
dst.nameStation as dep, ast.nameStation as arr
FROM Ticket
JOIN Trip
ON Ticket.idTrip = Trip.idTrip
JOIN Passanger
ON Ticket.idPassanger = Passanger.idPassanger
JOIN Train
ON Trip.idTrain = Train.idTrain
JOIN Price
ON Train.idTrain = Price.idTrain AND Ticket.wagon = Price.wagon
JOIN Station dst
ON Ticket.departureStation = dst.idStation
JOIN Station ast
ON Ticket.arrivalStation = ast.idStation