正确的问题,我正在编写配对日志,它的排名日志为不同的用户。他们现在希望它显示给每个人的最后一个等级,但是这里有相同用户名的多个输入是数据库的打印屏幕http://i.stack.imgur.com/Cr7Fv.png
那我怎么能这样做? 我试图限制它,但这不起作用我也尝试做多次查询但我不能那样做
<h3>General</h3>
<h3>Lieutenant General</h3>
<h3>Major General</h3>
<h3>Brigadier</h3>
<h3>Colonel</h3>
<h3>Lieutenant Colonel</h3>
<h3>Captain</h3>
<h3>Lieutenant</h3>
<h3>Second Lieutenant</h3>
<h3>Sub-Lieutenant</h3>
<h3>MSM</h3>
<h3>CCO4</h3>
<h3>CCO3</h3>
<h3>CCO2</h3>
<h3>CCO1</h3>
<h3>Quatermaster Sgt</h3>
<h3>Staff Sergeant</h3>
<h3>Sergeant</h3>
<h3>Specalist</h3>
<h3>Corporal</h3>
<h3>Lance Corporal</h3>
<h3>Private</h3>
<h3>Footsoldier</h3>
<h3>SNCOC</h3>
<h3>JNCOC</h3>
有等级
答案 0 :(得分:1)
您可以执行以下操作:
SELECT l1.*
FROM log l1 LEFT JOIN log l2
ON l1.username = l2.username AND l1.id < l2.id
WHERE l2.id IS NULL;
尝试一下,让我知道它是怎么回事。这是一个快速而又肮脏的小提琴:http://sqlfiddle.com/#!9/b4828/2