我希望在出版物表中找到最后一个类别 这是正确的SQL代码:
select id_categoria_id, max(update_time) from showgroups_publicacion group by id_categoria_id order by max(update_time) desc
1 | " 2015-05-04 18:25:19-04"
5 | " 2015-05-04 18:25:15-04"
0 | " 2015-05-04 18:24:35-04"
2 | " 2015-05-04 18:12:13-04"
在django我有这个:
cat_pub = Publicacion.objects.all().values('id_categoria').annotate(Max('update_time'))
cat_pub.query:
SELECT showgroups_publicacion.id_categoria_id, MAX(showgroups_publicacion.update_time) AS update_time__max FROM showgroups_publicacion GROUP BY showgroups_publicacion.id_categoria_id
0 | " 2015-05-04 18:24:35-04"
1 | " 2015-05-04 18:25:19-04"
2 | " 2015-05-04 18:12:13-04"
5 | " 2015-05-04 18:25:15-04"
我想在django中以max为单位订购,我该如何解决?
提前致谢。
答案 0 :(得分:2)
$gallery = $tpl['gallery_arr'];
for($i = $first = count($gallery) - 1; $i >= 0; $i-- ) {
$v = $gallery[$i];
if ( $k == $first ) {
...
}