|
12 | 12 | - 8: [ content.sql8, content.mongo8, content.desc8 ] |
13 | 13 | - 9: [ content.sql9, content.mongo9, content.desc9 ] |
14 | 14 | - 10: [ content.sql10, content.mongo10, content.desc10 ] |
| 15 | + - 11: [ content.sql11, content.mongo11, content.desc11 ] |
15 | 16 | --- |
16 | 17 | # table metadata, as meta.<key> |
17 | 18 | section: meta |
@@ -210,21 +211,40 @@ desc10: | |
210 | 211 | associated with the |
211 | 212 | orders. |
212 | 213 | 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 |
221 | 222 | 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 | + ] ) |
230 | 250 | ... |
0 commit comments