Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Apply aggregation function of column like sum , avg #210

Open
VarmaTech opened this issue Aug 12, 2020 · 1 comment
Open

How to Apply aggregation function of column like sum , avg #210

VarmaTech opened this issue Aug 12, 2020 · 1 comment

Comments

@VarmaTech
Copy link

Hi ,
how to get total sum of particular column , some thing like aggregation functionality , does sembast function this types of function.

@VarmaTech VarmaTech changed the title How to Aggregation function of Column like sum , avg How to Apply aggregation function of column like sum , avg Aug 12, 2020
@alextekartik
Copy link
Collaborator

Unfortunately no. However, data being in memory getting all the records and performing operation on the results does not cost much. example below to compute the sum and average of the fied age:

var store = intMapStoreFactory.store();
await store.addAll(db, [
  {'name': 'cat', 'age': 13},
  {'name': 'dog', 'age': 12},
  {'name': 'rabbit', 'age': 8}
]);
var ages = (await store.find(db)).map((snapshot) => snapshot['age']);

// Compute sum
var sum = ages.reduce((value, element) => value + element);
// Compute average
var average = sum / ages.length;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants