-- 查询价格大于或等于"超级本"价格的商品,并且按价格降序排列
//ANY用法
//与比较操作符联合使用,表示与子查询返回的任何值比较为 TRUE ,则返回 TRUE //简单案例
SELECT s1 FROM table1 WHERE s1 > ANY (SELECT s2 FROM table2)
1)在子查询中,返回的是 table2 的所有 s2 列结果(5,12,20)
2)然后将 table1 中的 s1 的值与之进行比较,
3)只要大于 s2 的任何值即表示为 TRUE,符合查询条件
SELECT * FROM tdb_goods WHERE goods_price > ANY(SELECT goods_price FROM tdb_goods WHERE goods_cate = '超级本') ORDER BY goods_price DESC; //IN用法
SELECT * FROM tdb_goods WHERE goods_price IN (SELECT goods_price FROM tdb_goods WHERE goods_cate = '超级本') ORDER BY goods_price DESC; in等价于= ANY
SELECT * FROM tdb_goods WHERE goods_price = ANY (SELECT goods_price FROM tdb_goods WHERE goods_cate = '超级本') ORDER BY goods_price DESC;
//复制编号为12,20的两条记录
SELECT * FROM tdb_goods WHERE goods_id IN (19,20);