• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

怎么用order by 查询 栏目下最贵的商品

mysql 搞代码 7年前 (2018-06-02) 107次浏览 已收录 0个评论

如何用order by 查询 栏目下最贵的商品
首先想到的用max来做 :  

html code

  select goods_id,goods_name,cat_id,shop_price from goods where shop_price in (select max(shop_price) from goods group by cat_id);     

欢迎大家阅读《怎么用order by 查询 栏目下最贵的商品》,跪求各位点评,by 搞代码

后来试着用order by 来做
[code=HTML]
select shop_price from goods order by shop_price desc;
+————+
| shop_price |
+————+
| 5999.00 |
| 3700.00 |
| 3010.00 |
| 2878.00 |
| 2625.00 |
| 2300.00 |
| 2298.00 |
| 2000.00 |
| 2000.00 |
| 1388.00 |
| 1337.00 |
| 1328.00 |
| 1311.00 |
| 1300.00 |
| 983.00 |
| 858.00 |
| 823.33 |
| 788.00 |
| 399.00 |
| 280.00 |
| 100.00 |
| 95.00 |
| 90.00 |
| 68.00 |
| 58.00 |
| 48.00 |
| 45.00 |
| 42.00 |
| 20.00 |
| 19.00 |
| 18.00 |
+————+
select shop_price from goods group by cat_id order by shop_price desc;
+————+
| shop_price |
+————+
| 3700.00 |
| 1388.00 |
| 823.33 |
| 399.00 |
| 95.00 |
| 90.00 |
| 68.00 |
| 48.00 |
| 20.00 |
+————+

[code=HTML]
发现出现的数据并不是最大的排在的前面,之后自以为是的加了个limit 1;结果只出现了一行数据
请问如何在此基础上得到每个栏目最大的数:
 [code=HTML]select shop_price from goods group by cat_id order by shop_price desc;[code=HTML]

——解决方案——————–
呵呵 自学的


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:怎么用order by 查询 栏目下最贵的商品
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址