sect<-c("Healthcare","Basic Materials","Utilities","Financial Services","Technology","Consumer"
"Defensive","Industrials","Communication Services","Energy","Real Estate","Consumer
Cyclical","NULL")
mcap<-c("3 - Large","2 - Mid","1 - Small")
df_total = data.frame()
start <- as.Date("01-01-14",format="%d-%m-%y")
end <- as.Date("18-03-20",format="%d-%m-%y")
theDate <- start
while (theDate <= end){
for (value1 in sect){
for (value2 in mcap){
date=theDate
sector<-value1
marketcap1<-value2
newquery("Select * from table where date='%s' and sector='%s' and marketcap='%s'",date,sector,marketcap1)
topdemo <- sqlQuery(dbhandle,newquery)
df=data.frame(topdemo)
df_total <- rbind(df_total,df)
}
}
theDate <- theDate + 1
}
在我的程序中,我做了一些 SQL 计算,而不是“选择”查询。我需要这段代码从 2014 年运行到 2020 年,但执行它需要很多时间。有什么办法可以减少执行时间?该数据库为每个市值和行业提供了许多股票价格。