library(RMySQL) conn <- dbConnect( MySQL(), user = dbuser, password = dbpass, dbname = dbname, host = dbhost, port = dbport ) consulta_frames <- " SELECT f.coins, CAST((f.elapsed_time / 1000) AS INT) FROM game g LEFT JOIN player p ON (p.id = g.player_id) LEFT JOIN frame f ON (f.game_id = g.id) WHERE ( f.id = ( SELECT id FROM frame WHERE game_id = g.id ORDER BY elapsed_time DESC LIMIT 1 ) ) GROUP BY g.id; "