gpt4 book ai didi

mysql - 尝试根据日期查找表的最大行时得到奇怪的值

转载 作者:太空宇宙 更新时间:2023-11-03 11:28:38 25 4
gpt4 key购买 nike

我正在尝试做一些我认为相对简单的事情。获取用户最后输入的值。我有一个表,用于跟踪他们所有名为 plan_activities_logs 的条目。我使用此语句获取有关单个用户的所有事件:

SELECT created_at as last_active, plan_id, plan_value 
from plan_activity_logs where plan_id IN (select id from plans where tile_id = 30);

它给了我一个看起来像这样的表:enter image description here

但是当我尝试做这样的事情时:

SELECT MAX(created_at) as last_active, plan_id, plan_value from plan_activity_logs where plan_id IN (select id from plans where tile_id = 30);

我明白了: enter image description here

虽然日期和 ID 正确,但计划值是错误的值。知道我做错了什么吗?

最佳答案

Any idea what I'm doing wrong?

你没有做错任何事。根据the manual

If ONLY_FULL_GROUP_BY is disabled, a MySQL extension to the standard SQL use of GROUP BY permits the select list, HAVING condition, or ORDER BY list to refer to nonaggregated columns even if the columns are not functionally dependent on GROUP BY columns. This causes MySQL to accept the preceding query. In this case, the server is free to choose any value from each group, so unless they are the same, the values chosen are nondeterministic, which is probably not what you want.

换句话说,这个行为是符合规范的。查询返回一个随机的非确定性值,因为您正在使用 MySql 非标准扩展来分组查询。

关于mysql - 尝试根据日期查找表的最大行时得到奇怪的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51900380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com