mysql group by问题

WBOY
Release: 2016-06-23 14:11:05
Original
900 people have browsed it

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楼的写法是我要的 谢谢大家。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!