Skip to content

Commit c05fe6d

Browse files
committed
fix group by alias order to match change in behavior
1 parent f5907dc commit c05fe6d

File tree

1 file changed

+71
-67
lines changed

1 file changed

+71
-67
lines changed

articles/cosmos-db/sql-query-group-by.md

Lines changed: 71 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ description: Learn about the GROUP BY clause for Azure Cosmos DB.
44
author: timsander1
55
ms.service: cosmos-db
66
ms.topic: conceptual
7-
ms.date: 04/10/2020
7+
ms.date: 05/19/2020
88
ms.author: tisande
99

1010
---
1111
# GROUP BY clause in Azure Cosmos DB
1212

1313
The GROUP BY clause divides the query's results according to the values of one or more specified properties.
1414

15-
> [!NOTE]
16-
> Azure Cosmos DB currently supports GROUP BY in .NET SDK 3.3 and above as well as JavaScript SDK 3.4 and above.
17-
> Support for other language SDK's is not currently available but is planned.
18-
1915
## Syntax
2016

2117
```sql
@@ -69,22 +65,24 @@ GROUP BY f.foodGroup
6965
Some results are (TOP keyword is used to limit results):
7066

7167
```json
72-
[{
73-
"foodGroup": "Fast Foods",
74-
"foodGroupCount": 371
75-
},
76-
{
77-
"foodGroup": "Finfish and Shellfish Products",
78-
"foodGroupCount": 267
79-
},
80-
{
81-
"foodGroup": "Meals, Entrees, and Side Dishes",
82-
"foodGroupCount": 113
83-
},
84-
{
85-
"foodGroup": "Sausages and Luncheon Meats",
86-
"foodGroupCount": 244
87-
}]
68+
[
69+
{
70+
"foodGroupCount": 183,
71+
"foodGroup": "Cereal Grains and Pasta"
72+
},
73+
{
74+
"foodGroupCount": 133,
75+
"foodGroup": "Nut and Seed Products"
76+
},
77+
{
78+
"foodGroupCount": 113,
79+
"foodGroup": "Meals, Entrees, and Side Dishes"
80+
},
81+
{
82+
"foodGroupCount": 64,
83+
"foodGroup": "Spices and Herbs"
84+
}
85+
]
8886
```
8987

9088
This query has two expressions used to divide results:
@@ -98,26 +96,28 @@ GROUP BY f.foodGroup, f.version
9896
Some results are:
9997

10098
```json
101-
[{
102-
"version": 1,
103-
"foodGroup": "Nut and Seed Products",
104-
"foodGroupCount": 133
105-
},
106-
{
107-
"version": 1,
108-
"foodGroup": "Finfish and Shellfish Products",
109-
"foodGroupCount": 267
110-
},
111-
{
112-
"version": 1,
113-
"foodGroup": "Fast Foods",
114-
"foodGroupCount": 371
115-
},
116-
{
117-
"version": 1,
118-
"foodGroup": "Sausages and Luncheon Meats",
119-
"foodGroupCount": 244
120-
}]
99+
[
100+
{
101+
"foodGroupCount": 183,
102+
"foodGroup": "Cereal Grains and Pasta",
103+
"version": 1
104+
},
105+
{
106+
"foodGroupCount": 133,
107+
"foodGroup": "Nut and Seed Products",
108+
"version": 1
109+
},
110+
{
111+
"foodGroupCount": 113,
112+
"foodGroup": "Meals, Entrees, and Side Dishes",
113+
"version": 1
114+
},
115+
{
116+
"foodGroupCount": 64,
117+
"foodGroup": "Spices and Herbs",
118+
"version": 1
119+
}
120+
]
121121
```
122122

123123
This query has a system function in the GROUP BY clause:
@@ -131,22 +131,24 @@ GROUP BY UPPER(f.foodGroup)
131131
Some results are:
132132

133133
```json
134-
[{
135-
"foodGroupCount": 371,
136-
"upperFoodGroup": "FAST FOODS"
137-
},
138-
{
139-
"foodGroupCount": 267,
140-
"upperFoodGroup": "FINFISH AND SHELLFISH PRODUCTS"
141-
},
142-
{
143-
"foodGroupCount": 389,
144-
"upperFoodGroup": "LEGUMES AND LEGUME PRODUCTS"
145-
},
146-
{
147-
"foodGroupCount": 113,
148-
"upperFoodGroup": "MEALS, ENTREES, AND SIDE DISHES"
149-
}]
134+
[
135+
{
136+
"foodGroupCount": 183,
137+
"upperFoodGroup": "CEREAL GRAINS AND PASTA"
138+
},
139+
{
140+
"foodGroupCount": 133,
141+
"upperFoodGroup": "NUT AND SEED PRODUCTS"
142+
},
143+
{
144+
"foodGroupCount": 113,
145+
"upperFoodGroup": "MEALS, ENTREES, AND SIDE DISHES"
146+
},
147+
{
148+
"foodGroupCount": 64,
149+
"upperFoodGroup": "SPICES AND HERBS"
150+
}
151+
]
150152
```
151153

152154
This query uses both keywords and system functions in the item property expression:
@@ -160,16 +162,18 @@ GROUP BY ARRAY_CONTAINS(f.tags, {name: 'orange'}), f.version BETWEEN 0 AND 2
160162
The results are:
161163

162164
```json
163-
[{
164-
"correctVersion": true,
165-
"containsOrangeTag": false,
166-
"foodGroupCount": 8608
167-
},
168-
{
169-
"correctVersion": true,
170-
"containsOrangeTag": true,
171-
"foodGroupCount": 10
172-
}]
165+
[
166+
{
167+
"foodGroupCount": 10,
168+
"containsOrangeTag": true,
169+
"correctVersion": true
170+
},
171+
{
172+
"foodGroupCount": 8608,
173+
"containsOrangeTag": false,
174+
"correctVersion": true
175+
}
176+
]
173177
```
174178

175179
## Next steps

0 commit comments

Comments
 (0)