All pastes #523833 Raw Edit

mrgenixus

public sql v1 · immutable
#523833 ·published 2007-05-30 22:26 UTC
rendered paste body
		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 		LIMIT 0,10and Returns: +------+-----+----------------------------+------------+------------+---+--------+| ord  | CID | name                       | effective  | expiration | x | score  |+------+-----+----------------------------+------------+------------+---+--------+| NULL |   1 | Buy One Get One Free!      | 1179986400 | 1180591200 | 1 | 113.65 | | NULL |   3 | Free Medium Drink w/Entree | 1180159200 | 1180677600 | 3 |   4.20 | | NULL |   5 | Hail To the Cheif          | 1180418400 | 1180591200 | 5 |   4.35 | +------+-----+----------------------------+------------+------------+---+--------+	I want to limit output to records with score > 4.20 so that I can count them...