如何在SQLITE中获取每个用户的最新进入日期?

发布于 2025-01-27 12:42:32 字数 403 浏览 1 评论 0原文

如果我通过auth_user.id 进行组,它会给我列表。如果分组的用户有多个行,我会在用户第一次填写我的表格时得到日期。如果我按日期订购(desc),则在他第一次填写表格的日期之前就订购了它。

如何获得他填写表格和用户分组的最后一次日期?现在我在这里:

SELECT * 
FROM answers
ORDER BY date DESC

它提供了所有用户的所有条目和每个日期下降。没关系。

SELECT * 
FROM answers
GROUP BY user_id
ORDER BY date DESC

现在,它提供了分组的数据,但是每个用户的第一个日期。如果分组,我该如何获得最后日期?

If I make a GROUP BY auth_user.id it gives me the list. If the users who are grouped has more than one rows I get the date when the user filled my form first time. If I order it by date (DESC), it orders it by the date when of the first time he filled the form.

How can I get the date of the last time when he filled the form and the users are grouped? Now I'm here:

SELECT * 
FROM answers
ORDER BY date DESC

It gives all the entries of all users and every dates descending. It's okay.

SELECT * 
FROM answers
GROUP BY user_id
ORDER BY date DESC

Now it gives grouped data but with the first date of every users. How can I get the last date if grouped?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2025-02-03 12:42:32

您可以使用max(date)获得每个用户的最新日期。

SELECT
  user_id,
  MAX(date)
FROM answers
GROUP BY user_id,
ORDER BY date DESC;

You can use max(date) to get the most recent date for each user.

SELECT
  user_id,
  MAX(date)
FROM answers
GROUP BY user_id,
ORDER BY date DESC;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文