SELECT x.*
FROM wordstyped x
JOIN
( SELECT idbook
, guiduser
, bookmarkletter
, MAX(attemptwrong) attemptwrong
FROM wordstyped
GROUP
BY idbook
, guiduser
, bookmarkletter
) y
ON y.idbook = x.idbook
AND y.guiduser = x.guiduser
AND y.bookmarkletter = x.bookmarkletter
AND y.attemptwrong = x.attemptwrong
http://sqlfiddle.com/#!9/135cf9/9
在我看来,视图在mysql中几乎是完全无用的——但是如果你必须拥有一个视图,那么你可以用这种方式重新编写上面的内容……
SELECT x.*
FROM wordstyped x
LEFT
JOIN wordstyped y
ON y.idbook = x.idbook
AND y.guiduser = x.guiduser
AND y.bookmarkletter = x.bookmarkletter
AND y.attemptwrong > x.attemptwrong
WHERE y.idbook IS NULL;
……它的比例很低,但至少可以使用一个视图。