SELECT count (*) FROM (SELECT (@pos:=@pos+1) AS ord, coupon.id AS CID, coupon.name AS name, UNIX_TIMESTAMP(coupon.effective) AS effective, UNIX_TIMESTAMP(coupon.expiration) AS expiration, coupon.id AS x, ( SELECT ( ( SELECT count( * ) FROM `vote_coupon` WHERE vote_coupon.coupon_id = x ) * .75 ) + ( ( SELECT ( 30 - ( to_days( expiration ) - to_days( now() ) ) ) FROM `coupon` WHERE ( expiration - now() ) <= 30 AND coupon.id = x GROUP BY coupon.id ) * .15 ) + ( ( SELECT count( * ) FROM `access` WHERE access.coupon_id = x ) * .10 ) ) AS score FROM `coupon` , `subcategory` , `category` , `business` WHERE coupon.effective <= now() AND coupon.expiration >= now() AND (SELECT (coupon.flags ^ 1)) #ACTIVE GROUP BY coupon.id HAVING score > 4.20 LIMIT 0,10 )