子查询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函数

 

posted @ 2016-11-04 10:51  Xiao|Deng  阅读(2326)  评论(0编辑  收藏  举报