简体   繁体   English

使用MonetDB在R中执行mySQL查询

[英]Executing mySQL queries in R with MonetDB

I am new to SQL and am using MonetDB to load a large file into R studio. 我是SQL新手,正在使用MonetDB将大文件加载到R studio中。 I have loaded my data as a db using monetDB, and would now like to execute the R code below on the data in this database: 我已经使用monetDB将数据作为db加载,现在想对该数据库中的数据执行以下R代码:

my_selection <- db_data %>% group_by(id) %>% 
  tally(. , sort = TRUE) %>% 
  top_n(100) %>% 
  select(id) 

Basically, I want to group my data by "id", tally and sort it, and select the 100 largest elements in it. 基本上,我想按“ id”对数据进行分组,对数据进行理算和排序,然后在其中选择100个最大的元素。 What would be an equivalent of this in SQL? 在SQL中相当于什么?

I am executing queries in the following way in R: 我在R中以以下方式执行查询:

my_selection <- dbGetQuery(connection,"SELECT * FROM my_table [INSERT REST OF CODE HERE]") 

That's depends on the DBMS you're using , 这取决于您使用的DBMS,

SQL-Server : SQL服务器:

SELECT TOP 100 id,sum(YourOtherColumn) as sum_c
FROM YourTable
GROUP BY id
ORDER BY sum_c DESC

MySQL : MySQL的:

SELECT id,sum(YourOtherColumn) as sum_c
FROM YourTable
GROUP BY id
ORDER BY sum_c DESC
LIMIT 100

If it's something else, tell me and I'll edit the answer. 如果还有其他问题,请告诉我,我将编辑答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM