子查询2-查询所有价格大于平均价格的商品,并且按价格降序排序
//查询所有价格大于平均价格的商品,并且按价格降序排序 //假定平均价格:5845.10 SELECT * FROM tdb_goods WHERE goods_price > 5845.10 ORDER BY goods_price DESC;
-- 使用子查询来实现
SELECT * FROM tdb_goods WHERE goods_price > (SELECT ROUND(AVG(goods_price),2) AS avg_price FROM tdb_goods) ORDER BY goods_price DESC;
知识点:
1、子查询语句:(SELECT ROUND(AVG(goods_price),2) AS avg_price FROM tdb_goods)
2、ORDER BY
3、DESC;
4、SELECT * FROM tdb_goods WHERE goods_price > avg_price
5、ROUND函数
无语言基础,自学python所做的各种笔记,欢迎大牛指点.