Data table support for aggregate functions

Hello @ahawes and welcome,

I think it will depend on which summary information you would like and how your tables are set up.

Using the DataTables API you can do something like the following to get the number of orders with a particular status (not a groupby).

num_rows=len(app_tables.orders.search(status='in_stock'))

To get a groupby-like operation, perhaps numpy could help:

import numpy as np

my_col=[r['order_status'] for r in app_tables.orders.search()]
unique, counts = numpy.unique(my_col, return_counts=True)
my_counts=dict(zip(unique, counts))

# returns a dictionary where each key represents the order status and the values are their counts

In terms of using SQL directly, the docs here say:

Users on Dedicated Hosting or Enterprise plans can access the data in their Data Tables using SQL directly. To get started, contact support@anvil.works to get your dedicated database credentials.

1 Like