【发布时间】:2019-04-16 18:44:26
【问题描述】:
我在 MariaDB 中有两个表,我需要在左表中显示它们的当前分数与历史表中的最新分数不同。
例如:
users
id name current_score
1 Bob 4
2 Tom 5
3 Fred 3
4 Tim 3
5 Ian 4
histories
id user_id score date
1 1 3 2018-11-13
2 1 4 2018-11-12
3 1 2 2018-11-11
4 2 5 2018-11-12
在上面我想显示 Bob,因为他的最新历史与他当前的得分不同,但不显示 Tom,因为他是匹配的
我尝试使用类似的东西:
SELECT u.id, u.name, u.current_score
FROM users u
where u.current_score not in
(select h.score from histories h where
h.user_id=u.id order by h.date desc limit 1)
这引发了错误:
#1235 - This version of MariaDB doesn't yet support
'LIMIT & IN/ALL/ANY/SOME subquery'
如果我删除限制 1,那么它会返回用户中的几乎所有行 - 每个表中有几千行,但我认为它应该返回大约 50 行,但它会返回 4,285 行中的 4,100 多行
【问题讨论】:
标签: mysql mariadb groupwise-maximum