Using an analytic query, I am trying to display the cumulative distribution of item quantities for all orders in a dataset named “orders,” which I based out of a bucket named dtOrders, which in turn features the data found in the sample Orders bucket. Here’s what I’ve done so far with the code so far.
CODE:
SELECT q.qty, q.custid, CUME_DIST() OVER (
PARTITION BY q.custid
ORDER BY q.qty
) AS `Quantity`
FROM orders AS q;
When I run this query, I get the following output.
OUTPUT:
[
{
"Quantity": 1,
"custid": "C41"
},
{
"Quantity": 1,
"custid": "C41"
},
{
"Quantity": 1,
"custid": "C13"
},
{
"Quantity": 1,
"custid": "C13"
},
{
"Quantity": 1,
"custid": "C13"
},
{
"Quantity": 1,
"custid": "C31"
},
{
"Quantity": 1,
"custid": "C35"
},
{
"Quantity": 1,
"custid": "C37"
}
]
As you can see, my current code outputs all quantities in the dataset as 1, which isn’t really what I want. Can someone be willing to help me out here? I would appreciate it. Thank you.