order by
排序:在結果集出來之後才有意義必須在where ,group by ,having 之後
desc(降序)/asc(升序)
用欄位排序
排序選擇,先根據cat_id,然後shop_price
select goods_name,cat_id,shop_price from goods where cat_id=4 order by shop_price desc;
升序排列取出前十名
select cat_id,shop_price,goods_name from goods order by cat_id ,shop_price;
select goods_id,goods_name from goods where cat_id=3 order by shop_price asc limit 10;
價格最高的前五名
的從第三名開始的三名(或者說是第三名到第五名)
mysql> select goods_name ,shop_price from goods order by shop_price desc limit 0,5;
mysql> select goods_name ,shop_price from goods order by shop_price desc limit 5; +----------------+------------+ | goods_name | shop_price | +----------------+------------+ | 多普达Touch HD | 5999.00 | | 诺基亚N96 | 3700.00 | | 诺基亚N85 | 3010.00 | | testPhone | 3000.00 | | 夏新T5 | 2878.00 | +----------------+------------+
取出每個類型中最新的產品
mysql> select goods_name ,shop_price from goods order by shop_price desc limit 2,3; +------------+------------+ | goods_name | shop_price | +------------+------------+ | 诺基亚N85 | 3010.00 | | testPhone | 3000.00 | | 夏新T5 | 2878.00 | +------------+------------+
mysql> select goods_name ,shop_price from goods order by shop_price desc limit 1; +----------------+------------+ | goods_name | shop_price | +----------------+------------+ | 多普达Touch HD | 5999.00 | +----------------+------------+
單列多行可以用in 再次過濾
多列多行可以用from 再次過濾
以上就是mysql order by的內容,更多相關內容請關注PHP中文網(www.php.cn)!