使用GROUP BY获取最后的条目 [英] Get the last entries using GROUP BY
本文介绍了使用GROUP BY获取最后的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了GROUP BY的问题。它返回它可以找到的第一个条目,但我希望它返回最后一个条目。这可能吗?
这是我的查询(准备好的查询):
SELECT stamp_user,stamp_date,stamp_type
FROM rws_stamps
WHERE stamp_date> =?
GROUP BY stamp_user
ORDER BY stamp_date DESC
我的表格如下所示:
我想要它返回的是第7行和第3行,但我得到1和2。 p>试试:
SELECT stamp_user,max(stamp_date),stamp_type
FROM rws_stamps
WHERE stamp_date> ; =?
GROUP BY stamp_user,stamp_type
I'm having problem with GROUP BY. It returns the first entry it could find, but I would like it to return the last entry. Is that possible?
Here is my query (prepared query):
SELECT stamp_user, stamp_date, stamp_type
FROM rws_stamps
WHERE stamp_date >= ?
GROUP BY stamp_user
ORDER BY stamp_date DESC
My table looks like this:
What I want it to return is row 7 and 3, but i get 1 and 2.
解决方案
Try:
SELECT stamp_user, max(stamp_date), stamp_type
FROM rws_stamps
WHERE stamp_date >= ?
GROUP BY stamp_user, stamp_type
这篇关于使用GROUP BY获取最后的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文