3 ms·
> db.sales.aggregate( [ { $group : { _id : null, totalPrice: { $sum: { $multiply: [ "$price", "$quantity" ] } }, averageQuantity: { $avg: "$quantity" }, count:
by takeda 9y ago
> db.sales.aggregate( [ { $group : { _id : null, totalPrice: { $sum: { $multiply: [ "$price", "$quantity" ] } }, averageQuantity: { $avg: "$quantity" }, count: { $sum: 1 } } } ] )
Now look at SQL version of it and tell me which one is easier:
SELECT SUM(price * quantity), AVG(quantity), COUNT(*) FROM sales;
- sethgecko 9y agoAm I the only one that finds it ridiculous that the way to query for data in SQL is by passing a string?