SELECT
COUNT(a)/COUNT(s)*100 as aratio,
COUNT(b)/COUNT(s)*100 as bratio,
COUNT(c)/COUNT(s)*100 as cratio,
COUNT(a),
COUNT(b),
COUNT(c),
COUNT(s)
FROM
(SELECT COUNT(cid) as a FROM images WHERE width > height AND category_id = 4 GROUP BY cid) as aq,
(SELECT COUNT(cid) as b FROM images WHERE width < height AND category_id = 4 GROUP BY cid) as bq,
(SELECT COUNT(cid) as c FROM images WHERE width = height AND category_id = 4 GROUP BY cid) as cq,
(SELECT COUNT(cid) as s FROM images WHERE category_id = 4 GROUP BY cid) as sq;
How can i make this request more effective?
it is possible with using
WITH. Move all queries toWITHand modify them a little: changeCOUNT(cid)toCOUNT(DISTINCT cid)and removeGROUP BYclause at all.