简体   繁体   English

RStatistics:在MySQL Query中将日期设置为变量

[英]RStatistics: Setting date as variable in MySQL Query

Connecting to a database via RMySQL I wrote some R-scripts - to make them easier: Is it possible to set the date in MySQL Query as a variable? 通过RMySQL连接到数据库我写了一些R脚本 - 使它们更容易:是否可以将MySQL Query中的日期设置为变量?

eg 例如

x<-"2012-12-01"

rs <- dbGetQuery(db,"**** where date between 'x' and '2012-12-31'")

Is there any possibility or is everything in "" just MySQL stuff? 是否有任何可能性或只是MySQL中的所有内容? Thanks! 谢谢!

Use paste to dynamically write your query: 使用paste动态编写查询:

x<-'2012-12-01'
query <-  paste("**** where date between '",x,"' and '2012-12-31'",sep='')

This will creates a query like: 这将创建一个查询,如:

"**** where date between '2012-12-01' and '2012-12-31'"

Then 然后

 rs <- dbGetQuery(db,query)

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

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