如何在R / SQL中连接不同长度的表?

时间:2013-10-29 19:48:07

标签: sql r

第一张表DailyOil,字段为DayofMonth,Month,Year,EXPL,AB,......

第二表HPower,包含字段HourEnding,Day,Month,Year,MWh1,MWh2,....

我想用HourEnding,Day,Month,Year,MWh1,MWh2,EXPL,AB

创建一个新表

注意第二个表作为添加时间字段,因此比油表长24倍。

R代码:

Library(sqldf)
df4 <- sqldf("SELECT HP.Month, HP.Day, HP.Year, HP.Express_Avg, HP.Platte_Avg, HP.Full_Avg, HP.CasperToGurley_Avg, HP.OgallallatoEthlyn_Avg, OD.EXPL, OD.PLATTE, OD.CASPERtoGUERNSEY 
              FROM HPower HP 
              LEFT JOIN DailyOil OD 
              on HP.Day = OD.DayofMonth and HP.Month = OD.Month and HP.Year = OD.Year")

Error in sqliteExecStatement(con, statement, bind.data) : 
  RS-DBI driver: (error in statement: near "FROM": syntax error)

0 个答案:

没有答案