我有數據表這樣更高效的查詢MYSQL
Table 1
Field1 Field2 Field3
00:00:01 Test1 10.0
00:00:01 Test2 7.3
00:00:01 Test3 11.03
00:00:10 Test1 11.0
00:00:10 Test2 17.3
00:00:10 Test3 15.03
01:00:01 Test1 5.0
01:00:01 Test2 4.3
01:00:01 Test3 4.03
01:00:10 Test1 5.0
01:00:10 Test2 4.3
01:00:10 Test3 4.03
02:00:01 Test1 78.0
02:00:01 Test2 43.3
02:00:01 Test3 19.03
02:00:10 Test1 79.0
02:00:10 Test2 46.3
02:00:10 Test3 14.03
我使用下面的查詢需要每個小時蔭的最大價值,但我找了一段時間更高效的在其他表保存
INSERT INTO table2 (Time, TYPE, Number)
SELECT Field1, Field2, max(Field3)
FROM table1
WHERE Field1 like '00:%' ;
INSERT INTO table2 (Time, TYPE, Number)
SELECT Field1, Field2, max(Field3)
FROM table1
WHERE Field1 like '01:%' ;
INSERT INTO table2 (Time, TYPE, Number)
SELECT Field1, Field2, max(Field3)
FROM table1
WHERE Field1 like '02:%' ;
..............
..............
to '23:%'