...
Code Block | ||
---|---|---|
| ||
SELECT date_trunc('minutes', used_on) as ts, count(*) FROM lippukala_order o, lippukala_code c WHERE o.id=c.id AND c.used_on between '2015-09-05 00:07:00'::timestamp AND '2015-09-05 14:00:00'::timestamp GROUP BY ts ORDER BY ts; |
Tilauksia, joissa yli 4 kpl viikonloppulippuja (Tracon 2018 event_id/product_id:t)
Code Block | ||
---|---|---|
| ||
SELECT ti_o.id,ti_op.count AS _cnt FROM tickets_order AS ti_o, tickets_orderproduct AS ti_op
WHERE ti_o.id=ti_op.order_id AND ti_o.event_id=49 AND ti_o.payment_date is not null
GROUP BY ti_o.id, ti_op.count, ti_op.product_id
HAVING (ti_op.product_id=130 AND ti_op.count > 4)
ORDER BY _cnt DESC; |
Minkä kokoisia tilauksia ihmiset tilaa
Code Block | ||||
---|---|---|---|---|
| ||||
In [6]: from tickets import OrderProduct from collections import Counter ops = OrderProduct.objects.filter( ...: order__event__slug='tracon2017', ...: order__confirm_time__isnull=False, ...: order__payment_date__isnull=False, ...: order__cancellation_time__isnull=True, ...: count__gte=1, ...: product__name__icontains='viikonloppu', ...: ) In [7]: ops.count() Out[7]:# 2170 In [8]: # Ei toimi enää, TypeError: 'OrderProduct' does not support indexing c = Counter() In [9]: for op in ops: ...: c[op.count] += 1 ...: In [10]: c Out[10]: Counter({1: 1171, 2: 665, 3: 211, 4: 76, 5: 36, 6: 6, 7: 3, 8: 1, 10: 1}) |
...