我创建了以下查询来制作一个“频率图”,显示特定值之间的行数:
SELECT CONCAT('0 - ', M.MaxField1) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1<M.MaxField1
UNION ALL
SELECT CONCAT((M.MaxField1), ' - ', (M.MaxField1*2)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1) AND P.Field1<(M.MaxField1*2)
UNION ALL
SELECT CONCAT((M.MaxField1*2), ' - ', (M.MaxField1*3)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*2) AND P.Field1<(M.MaxField1*3)
UNION ALL
SELECT CONCAT((M.MaxField1*3), ' - ', (M.MaxField1*4)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*3) AND P.Field1<(M.MaxField1*4)
UNION ALL
SELECT CONCAT((M.MaxField1*4), ' - ', (M.MaxField1*5)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*4) AND P.Field1<(M.MaxField1*5)
UNION ALL
SELECT CONCAT((M.MaxField1*5), ' - ', (M.MaxField1*6)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*5) AND P.Field1<(M.MaxField1*6)
UNION ALL
SELECT CONCAT((M.MaxField1*6), ' - ', (M.MaxField1*7)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*6) AND P.Field1<(M.MaxField1*7)
UNION ALL
SELECT CONCAT((M.MaxField1*7), ' - ', (M.MaxField1*8)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*7) AND P.Field1<(M.MaxField1*8)
UNION ALL
SELECT CONCAT((M.MaxField1*8), ' - ', (M.MaxField1*9)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*8) AND P.Field1<(M.MaxField1*9)
UNION ALL
SELECT CONCAT((M.MaxField1*9), ' - ', (M.MaxField1*10)) AS 'Part',COUNT(*)
FROM TABLE1 P, (SELECT (MAX(Field1)*(1/10)) AS MaxField1 FROM TABLE1) AS M
WHERE P.Field1>=(M.MaxField1*9)
有什么建议可以优化这个脚本,因为它非常耗时?