Maison >développement back-end >tutoriel php >mysql group by问题
id name value
1 a 3
2 a 4
3 a 5
如果我这样写
select * from table1
group by a
结果是
1 a 3
但是我希望要的是
3 a 5
应该怎么写?
写快了 sql语句 第二行改一下
group by name
抱歉
select * from (select * from table1 order by id desc) t
group by a
order by id DESC limit 1 也能实现类似的结果,但很可能不是你要的答案,建议你说出自己的本意。
SELECT * FROM (SELECT * FROM table1 ORDER BY id DESC) AS a GROUP BY name
SELECT * FROM (SELECT * FROM table1 ORDER BY id DESC) AS a GROUP BY name 我这里的a是sql的临时变量,不是你的name.
2楼的写法是我要的 谢谢大家。