SELECT sales_volume AS 'ty_volume',
transactions AS 'ty_trans',
offices AS 'ty_offices',
agents AS 'ty_agents',
(SELECT count(*)
FROM pb_survey_stats_final pb1
JOIN pb_survey_company_final pb2 on pb2.id = pb1.company_id
WHERE pb1.year = '2018' and pb1.sales_volume >= ty.sales_volume) AS 'ty_volume_rank',
(SELECT count(*)
FROM pb_survey_stats_final pb_stat
JOIN pb_survey_company_final pb_comp ON pb_comp.id = pb_stat.company_id
WHERE pb_stat.year = '2018' and pb_stat.transactions >= ty.transactions) AS 'ty_trans_rank'
FROM pb_survey_stats_final ty
WHERE ty.year = '2018'
AND ty.company_id = 0; There was a problem completing your request. Please try again.