【发布时间】:2020-03-19 09:51:17
【问题描述】:
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 年,但执行它需要很多时间。有什么办法可以减少执行时间?该数据库为每个市值和行业提供了许多股票价格。
【问题讨论】:
-
是的。避免
select *。只选择您需要的列。 -
我实际上对数据进行了大量计算。给出了“选择命令”以供参考。该程序基本上会遍历 2014 年以来的每个日期、市值和行业,并且计算的东西很少。如何减少时间?
标签: sql r sql-server parallel-processing database-management