sql - Executing mySQL queries in R with MonetDB -
i new sql , using monetdb load large file r studio. have loaded data db using monetdb, , execute r code below on data in database:
my_selection <- db_data %>% group_by(id) %>% tally(. , sort = true) %>% top_n(100) %>% select(id)
basically, want group data "id", tally , sort it, , select 100 largest elements in it. equivalent of in sql?
i executing queries in following way in r:
my_selection <- dbgetquery(connection,"select * my_table [insert rest of code here]")
that's depends on dbms you're using ,
sql-server :
select top 100 id,sum(yourothercolumn) sum_c yourtable group id order sum_c desc
mysql :
select id,sum(yourothercolumn) sum_c yourtable group id order sum_c desc limit 100
if it's else, tell me , i'll edit answer.
Comments
Post a Comment