0

通过 RMySQL 连接到数据库我写了一些 R 脚本 - 使它们更容易:是否可以将 MySQL Query 中的日期设置为变量?

例如

x<-"2012-12-01"

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

是否有任何可能性或者“”中的所有内容都只是 MySQL 的东西?谢谢!

4

1 回答 1

2

用于paste动态编写查询:

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

这将创建一个查询,如:

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

然后

 rs <- dbGetQuery(db,query)
于 2013-04-24T13:33:58.093 回答