[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>Oracle数据库SQL语句(四)
子查询(嵌套查询)
1、单行子查询
SELECT * FROM stu WHERE ID > (SELECT ID FROM stu WHERE NAME ='王五');
2、多行子查询
--IN 在什么范围内 SELECT * FROM stu WHERE ID IN (SELECT ID FROM stu WHERE CLASS =
'一班'); --ANY:表示任意的 --= ANY :和子查询中任意一个结果相等即可,相当于IN; SELECT * FROM stu WHERE ID =
ANY ( SELECT ID FROM stu WHERE CLASS = '一班'); --< ANY :比子查询返回的任意一个结果小即可,即小于返回结果
SELECT * FROM stu WHERE ID < ANY ( SELECT ID FROM stu WHERE CLASS = '一班'); -->
ANY :比子查询返回的任意一个结果大即可,即大于返回结果 SELECT * FROM stu WHERE ID > ANY ( SELECT ID FROM
stuWHERE CLASS = '一班'); --ALL:表示所有的 --= ALL :无意义,逻辑上也不成立。 SELECT * FROM stu
WHERE ID = ALL ( SELECT ID FROM stu WHERE CLASS = '一班'); --< ALL
:比子查询返回的所有的结果都小,即小于返回结果的最小值 SELECT * FROM stu WHERE ID < ALL ( SELECT ID FROM
stuWHERE CLASS = '三班'); --> ALL :比子查询返回的所有的结果都大,即大于返回结果的最大值 SELECT * FROM stu
WHERE ID > ALL ( SELECT ID FROM stu WHERE CLASS = '三班');
3、多列子查询
--多列子查询 SELECT ID,NAME,CLASS FROM stu WHERE ID IN ( SELECT MAX(ID) FROM stu
GROUP BY CLASS);
4、相关子查询
--相关子查询中,内部查询需引用外部查询的列,进行交互判断。 --相关子查询的执行方式是一行行操作。 --外部查询每执行一行操作,内部查询都要执行一次。
SELECT ID,NAME,CLASS FROM stu WHERE ID > (SELECT AVG(ID) FROM stu WHERE CLASS =
'三班');