我正在尝试选择具有最新时间戳的行。这是表格的一个示例:
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
| id | tester_name | frame | board_name | config | part_no | serial_no | license_count | legal_enabling | last_checked | log_name |
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
| 162936 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 6 | 974-331-44 | 302501d | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162937 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 7 | 974-331-44 | c0165ec | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162938 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 8 | 974-331-44 | c13100e | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162939 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 9 | 974-331-44 | 302c919 | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162941 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 14 | 974-331-44 | c00b41b | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162942 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 15 | 974-331-44 | c13101e | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162943 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 16 | 974-331-44 | 3014a1b | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 162944 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 17 | 974-331-44 | 302cc7e | | | 2015-08-01 19:48:48 | IGXLEventLog.8.1.2015.19.48.15.054.log |
| 166555 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 6 | 974-331-44 | 302501d | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166556 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 7 | 974-331-44 | c0165ec | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166557 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 8 | 974-331-44 | c13100e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166558 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 9 | 974-331-44 | 302c919 | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166560 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 14 | 974-331-44 | c00b41b | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166561 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 15 | 974-331-44 | c13101e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166562 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 16 | 974-331-44 | 3014a1b | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166563 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 17 | 974-331-44 | 302cc7e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
我用来获取上述内容的查询是
SELECT ti.*
FROM New_OTPMS.TBL_TESTER_ONLINE_INFO ti
INNER JOIN TBL_TESTER_LIST tl
ON ti.tester_name = tl.tester_name
WHERE ti.board_name = 'HSD-M'
AND tl.tester_type = 'UFLEX'
AND ti.tester_name = 'UFLEX-10'
ORDER BY ti.tester_name;
正如你所看到的,它只是从表中得到了所有东西。我想获取仅基于最新时间戳的行。注意:不是一行带有最新时间戳,而是基于config
的非重复行,带有SAME最新时间戳。
我想要的最新/行是
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
| id | tester_name | frame | board_name | config | part_no | serial_no | license_count | legal_enabling | last_checked | log_name |
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
| 166555 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 6 | 974-331-44 | 302501d | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166556 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 7 | 974-331-44 | c0165ec | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166557 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 8 | 974-331-44 | c13100e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166558 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 9 | 974-331-44 | 302c919 | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166560 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 14 | 974-331-44 | c00b41b | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166561 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 15 | 974-331-44 | c13101e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166562 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 16 | 974-331-44 | 3014a1b | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
| 166563 | UFLEX-10 | TEST_HEAD TH 1 | HSD-M | 17 | 974-331-44 | 302cc7e | | | 2015-07-29 02:32:39 | IGXLEventLog.7.29.2015.02.32.05.475.log |
+--------+-------------+------------------+------------+--------+---------+-----------+---------------+----------------+---------------------+-----------------------------------------+
对此有何帮助?
编辑:我编辑了上面的数据,以便与问题相对应。
答案 0 :(得分:0)
SELECT ti.*
FROM New_OTPMS.TBL_TESTER_ONLINE_INFO ti
INNER JOIN TBL_TESTER_LIST tl
ON ti.tester_name = tl.tester_name
WHERE ti.board_name = 'DC30'
AND tl.tester_type = 'UFLEX'
AND ti.tester_name = 'UFLEX-10'
ORDER BY ti.last_checked DESC LIMIT 1;
上面的sql应该可行。你的原始sql是按名称排序而不是时间。如果你只想要那一行最后一行,你可以在最后添加LIMIT 1。
答案 1 :(得分:0)
试试这个
SELECT ti.*
FROM New_OTPMS.TBL_TESTER_ONLINE_INFO ti
INNER JOIN TBL_TESTER_LIST tl
ON ti.tester_name = tl.tester_name
WHERE ti.board_name = 'DC30'
AND tl.tester_type = 'UFLEX'
AND ti.tester_name = 'UFLEX-10'
AND ti.last_checked = (
SELECT MAX(last_checked)
FROM New_OTPMS.TBL_TESTER_ONLINE_INFO
WHERE
board_name = 'DC30'
AND tester_name = 'UFLEX-10'
)