select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
select sq.name, sq.party, sq.months_in_office from (SELECT name, party, entered_office, TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 AS months_in_office, rank() over(partition by party order by TIMESTAMPDIFF(month, entered_office, CURDATE()) - 27 desc ) as 'rank' FROM us_senate) as sq where sq.rank <= 2 ;
SELECT name, party, months_in_office FROM ( SELECT name, party, months_in_office, row_number() over (partition by party order by months_in_office desc) as by_party_order FROM ( SELECT party, name, entered_office, timestampdiff(MONTH, entered_office, now()) - 1 as months_in_office FROM us_senate ) x ) x WHERE x.by_party_order <= 2;
SELECT name, party, months_in_office FROM ( SELECT name, party, months_in_office, row_number() over (partition by party order by months_in_office desc) as by_party_order FROM ( SELECT party, name, entered_office, timestampdiff(MONTH, entered_office, now()) - 1 as months_in_office FROM us_senate ) x ) x WHERE x.by_party_order <= 2;
SELECT name, party, months_in_office FROM ( SELECT name, party, months_in_office, row_number() over (partition by party order by months_in_office desc) as by_party_order FROM ( SELECT party, name, entered_office, timestampdiff(MONTH, entered_office, now()) - 1 as months_in_office FROM us_senate ) x ) x WHERE x.by_party_order <= 2;
SELECT name, party, months_in_office FROM ( SELECT name, party, months_in_office, row_number() over (partition by party order by months_in_office desc) as by_party_order FROM ( SELECT party, name, entered_office, timestampdiff(MONTH, entered_office, now()) - 1 as months_in_office FROM us_senate ) x ) x WHERE x.by_party_order <= 2;
SELECT name, party, months_in_office FROM ( SELECT name, party, months_in_office, row_number() over (partition by party order by months_in_office desc) as by_party_order FROM ( SELECT party, name, entered_office, timestampdiff(MONTH, entered_office, now()) - 1 as months_in_office FROM us_senate ) x ) x WHERE x.by_party_order <= 2;