Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT INTO newtwons (net, batchid, userid) SELECT sum(net), batch_id, user_id FROM hands WHERE created_at = CURDATE() GROUP BY batch_id, user_id;
- # grab all new batch-ids from today:
- select distinct(batch_id), user_id from hands where DAY(created_at) = DAY(CURDATE()) and MONTH(created_at) = MONTH(CURDATE()) and YEAR(created_at) = YEAR(CURDATE());
- # this results (from prev. couple of months records to be between 100-200 records and will prob. grow)
- # loop through each batchid collected and make a new record after finding the sum from each
- # each batch would have anywhere between 10-200 records each
- foreach record do
- mysql> select sum(net) from hands where batch_id = '77a1d447-7abc-4c22-aac0-071c23cbeb7c';
- insert into netwons net, batchid, userid;
- end
- # then go ahead and insert that into a diff. table
Add Comment
Please, Sign In to add comment