$sort(내림차순, 오름차순)

Hanbyul·2023년 11월 15일

mongoDB

목록 보기
6/16

$sort연산자에서 필드 값이 -1 이면 내림차순 정렬, 1이면 오름차순 정렬을 수행함.

ex. mongoDB

db.order.aggregate([{$group:
	{_id:"$cust_id",
		total_price:{$sum:"$price"}}},
			{$sort:{total_price:-1}}]);
ex. oracle sql

SELECT cust_id AS "_id", SUM(price) AS "total_price"
FROM order
GROUP BY cust_id
ORDER BY "total_price" DESC;

위 위 mongoDB 질의와 아래 sql 질의는 같은 결과.

profile
공부공부

0개의 댓글