Guest User

Untitled

a guest
Jul 19th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. 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;
  2.  
  3. # grab all new batch-ids from today:
  4.  
  5. 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());
  6.  
  7. # this results (from prev. couple of months records to be between 100-200 records and will prob. grow)
  8.  
  9. # loop through each batchid collected and make a new record after finding the sum from each
  10. # each batch would have anywhere between 10-200 records each
  11.  
  12. foreach record do
  13. mysql> select sum(net) from hands where batch_id = '77a1d447-7abc-4c22-aac0-071c23cbeb7c';
  14. insert into netwons net, batchid, userid;
  15. end
  16.  
  17. # then go ahead and insert that into a diff. table
Add Comment
Please, Sign In to add comment