Skip to content

Commit 7089c0f

Browse files
committed
DOCS-880 add count of distinct groupings
1 parent 9734ca9 commit 7089c0f

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

source/includes/table-sql-to-agg-examples.yaml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rows:
1212
- 8: [ content.sql8, content.mongo8, content.desc8 ]
1313
- 9: [ content.sql9, content.mongo9, content.desc9 ]
1414
- 10: [ content.sql10, content.mongo10, content.desc10 ]
15+
- 11: [ content.sql11, content.mongo11, content.desc11 ]
1516
---
1617
# table metadata, as meta.<key>
1718
section: meta
@@ -210,21 +211,40 @@ desc10: |
210211
associated with the
211212
orders.
212213
sql10: |
213-
.. code-block:: sql
214-
215-
SELECT cust_id,
216-
SUM(li.qty) as qty
217-
FROM orders o,
218-
order_lineitem li
219-
WHERE li.order_id = o.id
220-
GROUP BY cust_id
214+
.. code-block:: sql
215+
216+
SELECT cust_id,
217+
SUM(li.qty) as qty
218+
FROM orders o,
219+
order_lineitem li
220+
WHERE li.order_id = o.id
221+
GROUP BY cust_id
221222
mongo10: |
222-
.. code-block:: javascript
223-
:emphasize-lines: 2-5
224-
225-
db.orders.aggregate( [
226-
{ $unwind: "$items" },
227-
{ $group: { _id: "$cust_id",
228-
qty: { $sum: "$items.qty" } } }
229-
] )
223+
.. code-block:: javascript
224+
:emphasize-lines: 2-5
225+
226+
db.orders.aggregate( [
227+
{ $unwind: "$items" },
228+
{ $group: { _id: "$cust_id",
229+
qty: { $sum: "$items.qty" } } }
230+
] )
231+
desc11: |
232+
Count the number of distinct
233+
``cust_id``, ``ord_date`` groupings.
234+
sql11: |
235+
.. code-block:: sql
236+
237+
SELECT COUNT(*)
238+
FROM (SELECT cust_id, ord_date
239+
FROM orders
240+
GROUP BY cust_id, ord_date) as DerivedTable
241+
mongo11: |
242+
.. code-block:: javascript
243+
:emphasize-lines: 2-4
244+
245+
db.orders.aggregate( [
246+
{ $group: { _id: { cust_id: "$cust_id",
247+
ord_date: "$ord_date" } } },
248+
{ $group: { _id: null, count: { $sum: 1 } } }
249+
] )
230250
...

0 commit comments

Comments
 (0)