Created
May 2, 2011 07:51
Revisions
-
gravis created this gist
May 2, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ select orders.user_id, email, sum(stake) as mises_perdantes, 5.00 as bonus from bets join orders on orders.id = bets.order_id join users on orders.user_id = users.id join races on races.id = bets.race_id where races.start_time::date BETWEEN '2011-04-29' AND '2011-04-30' and bets.status = 'paid' and cancelled_by is null and bets.bet_type_id = 9 -- bet5 and win = 0 group by orders.user_id, users.email having sum(stake) >= 20; INSERT INTO exceptional_bonus (money_account_id, amount, reason, created_at, updated_at) SELECT money_accounts.id, 5.00, 'Operation 29-30 avril 2011', now(), now() from bets join orders on orders.id = bets.order_id join users on orders.user_id = users.id join money_accounts on money_accounts.user_id = users.id and orders.currency_code = money_accounts.currency_code where bets.start_time::date BETWEEN '2011-04-29' AND '2011-04-30') and bets.status = 'paid' and cancelled_by is null and bets.bet_type_id = 9 -- bet5 and win = 0 group by money_accounts.id having sum(stake) >= 20;