select
t2.epoch,
t2.`value`
from
(
select
t1.`value`,
t1.epoch,
(select `value` from data where epoch < t1.epoch ORDER BY epoch DESC LIMIT 1) prev_value,
(select `value` from data where epoch > t1.epoch ORDER BY epoch LIMIT 1) next_value
from data t1
where t1.value = 0
order by t1.epoch
) t2
where t2.prev_value = 0 and t2.next_value = 0
select
t3.id,
t3.Customer,
t3.weight,
t4.others
from
(
select
t1.id,
t1.Customer,
t2.weight
from Order t1
inner join
(
select
Order_id,
sum(Weight) as weight
from Order_position
group by Order_id
) t2 on t2.Order_id = t1.id
) t3
inner join
(
select
Order_id,
sum(Price * Value) as others
from Order_other
group by Order_id
) t4 on t4.Order_id = t3.id
select
t3.Continent,
t3.Region,
sum(t3.Countries),
sum(t3.LifeDuration),
sum(t3.Population),
sum(t3.Cities),
sum(t4.Languages)
from
(
select
t1.Code,
t1.Continent,
t1.Region,
t1.Countries,
t1.LifeDuration,
t1.Population,
t2.Cities
from
(
select
Code,
Continent,
Region,
count(Name) as Countries,
ROUND(AVG(LifeExpectancy), 2) as LifeDuration,
SUM(Population) as Population
from country
group by Code,Continent,Region
) t1 left join
(
select
CountryCode,
count(Name) as Cities
from city
group by CountryCode
) t2 on t2.CountryCode = t1.Code
) t3 left join
(
select
CountryCode,
count(Language) as Languages
from countrylanguage
) t4 on t4.CountryCode = t3.Code
group by t3.Continent,t3.Region
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