日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql查询嵌套where_MySQL-10(where /from 嵌套查询)

發布時間:2025/3/20 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql查询嵌套where_MySQL-10(where /from 嵌套查询) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 引出: 按照網站,取出Product_id 最大的

select product_name,product_price,product_id

from tb_name

order by product-id

limit 0,1;

思考: 在這里是利用 limit 語句來實現,再考慮用子查詢來實現

#? 這里考慮分兩步來實現

1.先使用max聚合找到 product_id 最大的值

即:

select max(product_id), product_name, product_price

from tb_name

2.再使用 where product-id = ‘max中的最大值’,假設max_product_id = 33;

即:

select? product_id, product_name, product_price

from tb_name

where product_id = 33;

綜合 1,2 兩步

即:

select product_id ,product_name, product_price

from tb_name

where product =(select max(product_id),product_name,product_price from tb_name? )

到此:我們就引出了子查詢的概念

where 子查詢,即將內層查詢的結果作為外層查詢的? where 條件值

強化:

將tb_name 中,取出每個cat_id 下 product_id 最大的商品信息

第一:

select max(product_id),product_name

from tb_name

group by cat_id; # 這里先按照cat_id 取出每個欄目下最大的product_id

第二:

select product_id ,product_price ,cat_id

from tb_name

where product in ( select max(product_id,product_name,product_price

from tb_name

group by cat_id));

# from 子查詢

select * from (

select product_id ,product _name,product_price

from tb_name

order by cat_id desc,

product_price asc)

as temp

group by cat_id;

mark: 2020年正月初六

總結

以上是生活随笔為你收集整理的mysql查询嵌套where_MySQL-10(where /from 嵌套查询)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。