All pastes #523907 Raw Edit

mrgenixus

public sql v1 · immutable
#523907 ·published 2007-05-30 22:54 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                HAVING score > 4.20                LIMIT 0,10with the "HAVING" Statement, this gives a syntax error @ 'GROUP BY coupon.id ...'without the 'HAVING' statement this returns..and 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...