您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql group by问题

2024/6/8 4:45:25发布106次查看
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楼的写法是我要的 谢谢大家。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product