Skip to content

Instantly share code, notes, and snippets.

@linxlad
Created July 9, 2015 10:00
Show Gist options
  • Save linxlad/f77e98936f3fe34dad23 to your computer and use it in GitHub Desktop.
Save linxlad/f77e98936f3fe34dad23 to your computer and use it in GitHub Desktop.
Price range percentages
SELECT
concat(round((Count(case when pr.`price` > 0 AND pr.`price` <= 50000 then 1 end) / Count(1) * 100), 2 ),'%') As '£0 - £50K',
concat(round((Count(case when pr.`price` > 50000 AND pr.`price` <= 100000 then 1 end) / Count(1) * 100), 2 ),'%') As '£50 - £100K',
concat(round((Count(case when pr.`price` > 100000 AND pr.`price` <= 150000 then 1 end) / Count(1) * 100), 2 ),'%') As '£100 - £150K',
concat(round((Count(case when pr.`price` > 150000 AND pr.`price` <= 200000 then 1 end) / Count(1) * 100), 2 ),'%') As '£150K - £200K',
concat(round((Count(case when pr.`price` > 200000 AND pr.`price` <= 250000 then 1 end) / Count(1) * 100), 2 ),'%') As '£200K - £250K',
concat(round((Count(case when pr.`price` > 250000 AND pr.`price` <= 300000 then 1 end) / Count(1) * 100), 2 ),'%') As '£250K - £300K',
concat(round((Count(case when pr.`price` > 300000 AND pr.`price` <= 350000 then 1 end) / Count(1) * 100), 2 ),'%') As '£300K - £350K',
concat(round((Count(case when pr.`price` > 350000 AND pr.`price` <= 400000 then 1 end) / Count(1) * 100), 2 ),'%') As '£350K - £400K',
concat(round((Count(case when pr.`price` > 400000 AND pr.`price` <= 450000 then 1 end) / Count(1) * 100), 2 ),'%') As '£400K - £450K',
concat(round((Count(case when pr.`price` > 450000 AND pr.`price` <= 500000 then 1 end) / Count(1) * 100), 2 ),'%') As '£450K - £500K',
concat(round((Count(case when pr.`price` > 500000 AND pr.`price` <= 550000 then 1 end) / Count(1) * 100), 2 ),'%') As '£500K - £550K',
concat(round((Count(case when pr.`price` > 550000 AND pr.`price` <= 600000 then 1 end) / Count(1) * 100), 2 ),'%') As '£550K - £600K',
concat(round((Count(case when pr.`price` > 600000 AND pr.`price` <= 650000 then 1 end) / Count(1) * 100), 2 ),'%') As '£600K - £650K',
concat(round((Count(case when pr.`price` > 650000 AND pr.`price` <= 700000 then 1 end) / Count(1) * 100), 2 ),'%') As '£650K - £700K',
concat(round((Count(case when pr.`price` > 700000 AND pr.`price` <= 750000 then 1 end) / Count(1) * 100), 2 ),'%') As '£700K - £750K',
concat(round((Count(case when pr.`price` > 750000 AND pr.`price` <= 800000 then 1 end) / Count(1) * 100), 2 ),'%') As '£750K - £800K',
concat(round((Count(case when pr.`price` > 800000 AND pr.`price` <= 850000 then 1 end) / Count(1) * 100), 2 ),'%') As '£800K - £850K',
concat(round((Count(case when pr.`price` > 850000 AND pr.`price` <= 900000 then 1 end) / Count(1) * 100), 2 ),'%') As '£850K - £900K',
concat(round((Count(case when pr.`price` > 900000 AND pr.`price` <= 950000 then 1 end) / Count(1) * 100), 2 ),'%') As '£900K - £950K',
concat(round((Count(case when pr.`price` > 950000 AND pr.`price` <= 1000000 then 1 end) / Count(1) * 100), 2 ),'%') As '£950K - £1M',
concat(round((Count(case when pr.`price` > 1000000 then 1 end) / Count(1) * 100), 2 ),'%') As '£1M+',
Count(1) AS total
FROM
properties p
JOIN property_revisions pr ON p.id = pr.property_id
AND pr.flag = 1
WHERE
p.listing_type = "selling"
AND p.created >= NOW() - INTERVAL 12 MONTH;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment