如果只有这两个字段,很简单,group by 加 min就行了,如果多于这两个字段,请参考
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=6420
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=6420
解决方案 »
- 读写比较平衡,数据量在100G,选mysql还是postgresql呢?
- netbeans IDE中查看MySQL数据总是报错,在web项目中能检测到数据
- 有两种应用情况求SQL语句。
- Parameter index out of range (1 > number of parameters, which is 0).
- 求mysql查询语句
- MYSQL使用不了TOP是吗?
- 关于SQL性能优化,求助!!!
- 那位仁兄能帮我解决问题!!!!?(关于PHP和MYSQL)
- Mysql control center 0.8.10 在windows 2000 下连接linux下的Mysql数据库,不通?
- c#连接mysql模糊查询中文的问题
- 各位哥哥,帮帮小妹。。。。
- 书上这个例子这个语句为什么老提示错误?
第一行就是最小价格的商品
我实际还有一些字段,照你的写法这样select xxx,xxx,xx,xxx,name,min(price) as price from shop group by name;列出的结果是不正确的..
from shop b
使用子查詢聚合
请参考
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=6420
where
not exists
(select * from tablename b
where
a.name = b.name
and
a.price < b.price
)
where price in
(select min(price) from tablename)
select * from tablename
where price in
(select min(price) from tablename group by name)
group by name
from tA
group by name
having prices<=all(
selcet min(prince)
from ta
group by name
)