>  기사  >  데이터 베이스  >  MySQL 주문 기준

MySQL 주문 기준

黄舟
黄舟원래의
2017-01-16 13:09:001292검색

order by
Sort: 결과 집합이 나온 후에만 의미가 있습니다. where, group by, 그리고
desc(내림차순)/asc(오름차순)
필드별 정렬

shop_price를 사용하여 내림차순으로 정렬

select goods_name,cat_id,shop_price from goods where cat_id=4 order by shop_price desc;

여러 정렬 선택, 먼저 cat_id를 기준으로 한 다음 shop_price


select cat_id,shop_price,goods_name from goods order by cat_id ,shop_price;

limit 제한 [pos, 선택적 오프셋 ] 수량


오름차순으로 정렬하여 상위 10개를 꺼냅니다

select goods_id,goods_name from goods where cat_id=3 order by shop_price asc limit 10;

가격이 가장 높은 상위 5개


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 | 
+----------------+------------+

세 번째 이름(또는 세 번째 ~ 다섯 번째)부터 가격이 가장 높은 3인


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 | 
+----------------+------------+

기법: [판사] where] [그룹 group_by] [필터 있음] [정렬 기준] [필터 제한]


각 유형의 최신 제품 가져오기

select cat_id, goods_id ,goods_name from(
(select cat_id,goods_id ,goods_name from goods order by cat_id desc,goods_id desc ) as tmp
)group by cat_id order by cat_id desc;
rrree

쿼리 결과는 다음과 같습니다.

단일 열과 단일 행을 사용할 수 있음 = again
단일 열과 여러 행을 필터링하려면 in을 사용할 수 있습니다. 여러 열과 여러 행으로 다시 필터링하려면
을 사용하여 다시 필터링하려면

위 내용은 mysql order by 내용입니다. 더 많은 관련 내용은 PHP 중국어 홈페이지(www.php.cn)를 주목해주세요!


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:mysql null 와' '다음 기사:mysql null 와' '