ทำ Index แล้ว
mysql> desc gldtrndat;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| Rec | int | YES | MUL | NULL | |
| Cst | char(2) | YES | MUL | NULL | |
| PT | int | YES | MUL | NULL | |
+-------+----------+------+-----+---------+-------+
10 rows in set (0.00 sec)
mysql> select rec from gldtrndat where cst = 'C9' order by rec desc limit 0,1;
+-------+
| rec |
+-------+
| 26438 |
+-------+
1 row in set (1 min 6.72 sec)
mysql> select rec from gldtrndat where cst = 'C1' order by rec desc limit 0,1;
+---------+
| rec |
+---------+
| 1091000 |
+---------+
1 row in set (22.98 sec)
mysql>
MySQL select ช้ามากแก้ยังไงครับ
mysql> desc gldtrndat;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| Rec | int | YES | MUL | NULL | |
| Cst | char(2) | YES | MUL | NULL | |
| PT | int | YES | MUL | NULL | |
+-------+----------+------+-----+---------+-------+
10 rows in set (0.00 sec)
mysql> select rec from gldtrndat where cst = 'C9' order by rec desc limit 0,1;
+-------+
| rec |
+-------+
| 26438 |
+-------+
1 row in set (1 min 6.72 sec)
mysql> select rec from gldtrndat where cst = 'C1' order by rec desc limit 0,1;
+---------+
| rec |
+---------+
| 1091000 |
+---------+
1 row in set (22.98 sec)
mysql>