我想从mysql中选择最新的数据,所以我运行下面的sql,但是我得到的next_visit_time
与max create_time
的行的实际值不匹配。所以我检查了数据,我发现最新的数据是null
,所以我使用Any_value函数时guest guest Mysql不会得到null值。
如果值为null,如何获取any_value()?
SELECT
student_id,
max(created_time) as created_time,
any_value(next_visit_time) as next_visit_time
FROM
student_visit_record
GROUP BY
student_id
答案 0 :(得分:0)
SELECT DISTINCT
student_id,
max(created_time),
next_visit_time
FROM
student_visit_record
WHERE
next_visit_time IS NOT NULL OR next_visit_time IS NULL
GROUP BY
student_id
这可能是你想要的任何机会吗? See SQL fiddle