选择糟糕的表现

时间:2016-11-29 12:18:26

标签: mysql subquery greatest-n-per-group database-performance

这是我的查询,执行需要很长时间。我可以使用内连接吗?我只在一张桌子上工作。

SELECT imei,csv_data_table.time,phone_model,test_unique_id 
FROM verveba_mos.csv_data_table
WHERE time = (SELECT MAX(time) FROM csv_data_table
              T1 WHERE csv_data_table.imei=T1.imei) 

2 个答案:

答案 0 :(得分:0)

您可以使用xi <- mtcars$mpg plot(density(xi, kernel = "gaussian"), lwd = 2) auto.dens <- density(xi, kernel = "gaussian") h <- auto.dens$bw # bandwidth for kernel x0 <- auto.dens$x # points for prediction fx0 <- NULL for (j in 1:length(x0)) { t <- abs(x0[j]-xi)/h K <- (1/sqrt(2*pi))*exp(-(t^2)/2) fx0 <- c(fx0, sum(K)/(length(t)*h)) } lines(x0, fx0, col = "red", lty = "dotted") JOIN来执行此操作,但这并不一定意味着它会更快:

NOT EXISTS()

EXISTS()

SELECT imei,csv_data_table.time,phone_model,test_unique_id FROM verveba_mos.csv_data_table t WHERE NOT EXISTS(SELECT 1 FROM csv_data_table s WHERE t.imei= s.imei AND s.time > t.time)

JOIN

答案 1 :(得分:0)

SELECT t1.imei, t1.time, t1.phone_model, t1.test_unique_id
 FROM csv_data_table t1
 JOIN (select imei, max(time) time from csv_data_table group by imei) t2
   ON (t1.imei = t2.imei and t1.time = t2.time)

如果您还没有索引,还应考虑在csv_data_table(imei, time)上添加索引。