有人可以就这里的错误提出建议吗?
我正在尝试选择一个充满结果的表,有些是重复的,但时间戳不同,所以我想过滤掉最新的日期。
我正在使用以下sql查询,但它只是不断抛出错误?
$sql = "(SELECT *
FROM measrate
WHERE TRANS_TIME = (SELECT MAX(TRANS_TIME) FROM measrate)";
答案 0 :(得分:1)
sql = "(SELECT * FROM measrate WHERE TRANS_TIME = (SELECT MAX(TRANS_TIME) FROM measrate))";
忘了最后一个支架
答案 1 :(得分:1)
首先,初始括号应该是不必要的:
SELECT m.*
FROM measrate m
WHERE TRANS_TIME = (SELECT MAX(TRANS_TIME) FROM measrate m2);
其次,如果您只想要某个组的最长时间 - 比如基于列result
- 那么将其修改为相关子查询:
SELECT m.*
FROM measrate m
WHERE TRANS_TIME = (SELECT MAX(TRANS_TIME) FROM measrate m2 WHERE m2.result= m.result);