我尝试了以下查询
select a.id,a.vehicle_id,a.info_datetime
from table_name a
join (select id, max(info_datetime) as maxdt from table_name group by vehicle_id) as b
on a.info_datetime = b.maxdt
答案 0 :(得分:1)
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
echo $image[0];
答案 1 :(得分:0)
您的尝试即将到来,但是您也需要通过id
加入:
select a.id,a.vehicle_id,a.info_datetime
from table_name a
join (
select vehicle_id, max(info_datetime) as maxdt from table_name group by vehicle_id
) as b on a.info_datetime = b.maxdt and a.vehicle_id = b.vehicle_id
另一种方法是使用相关子查询进行过滤:
select a.*
from table_name a
where a.info_datetime = (
select max(b.info_datetime) from table_name b where b.vehicle_id = a.vehicle_id
)
答案 2 :(得分:0)
SELECT id, vehicle_id, info_datetime
FROM table_name
WHERE id in (
select max(m2.id) from table_name m2 group by m2.vehicle_id)
ORDER BY vehicle_id asc,info_datetime DESC