SELECT a.stamper,
a.city,
AVG(a.speed) AS AVG_SPEED,
MAX(a.speed) AS MAX_SPEED,
(select b.station
from data as b
where b.city=a.city and
b.speed=max(a.speed)
limit 1) as max_speed_station
FROM data a
GROUP BY a.stamper,
a.city;
select a.*,
b.station as max_speed_station
from (SELECT stamper,
city,
AVG(speed) AS AVG_SPEED,
MAX(speed) AS MAX_SPEED
FROM data
GROUP BY stamper,
city) as a
left join data as b
on a.city=b.city and
a.MAX_SPEED=b.speed;
select id,
category_id,
title,
row_number() over(partition by category_id) as rownum
from articles
order by rownum
limit 10;
with
all_ranges as (
SELECT tsrange(generate_series,
generate_series + interval '30' minute,
'()') as range
FROM generate_series(current_date::timestamp + interval '9' hour,
current_date::timestamp + interval '18' hour,
'30 minutes'))
select rooms.id as room_id,
concat(to_char(lower(ar.range), 'HH24:MI'),
' - ',
to_char(upper(ar.range), 'HH24:MI')) as timerange
from all_ranges as ar
cross join rooms
where not exists (select 1
from reservations as rt
where rooms.id=rt.room_id and
ar.range && rt.occurrence)
order by 1;
CREATE TABLE comments(
id_comment INT(255) NOT NULL AUTO_INCREMENT PRIMARY KEY,
comment TEXT not null,
id_people int(8) unsigned not null,
foreign key(id_people) references peoples(people_id) on update cascade on delete cascade);