You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get a sum of bills for each category. I see the .sum() only seems to work on the selected table but not the joined table.
How can I return a column similar to the 'amountOfBills' count but a sum of the 'amount' column in the related bills?
Thanks.
Stream<List<CategoryWithTypes>> streamCategoryWithTypes() {
final amountOfBills = bills.id.count();
// add sum of bills [ ISSUE HERE]
final sumOfBills = bills.amount.sum();
final query = select(categories).join([
leftOuterJoin(types, types.id.equalsExp(categories.typeId)),
leftOuterJoin(bills, bills.categoryId.equalsExp(categories.id) & bills.deletedAt.isNull()),
]);
// order by category name ascending
query.orderBy([OrderingTerm.asc(categories.name)]);
query.addColumns([bills.id.count()]);
query.groupBy([categories.id]);
// see next section on how to parse the result
return query.watch().map((rows) {
return rows.map((row) {
return CategoryWithTypes(
row.readTable(categories),
row.readTable(types),
row.read(amountOfBills),
row.read(sumOfBills)
);
}).toList();
});
}
The text was updated successfully, but these errors were encountered:
I am trying to get a sum of bills for each category. I see the .sum() only seems to work on the selected table but not the joined table.
How can I return a column similar to the 'amountOfBills' count but a sum of the 'amount' column in the related bills?
Thanks.
The text was updated successfully, but these errors were encountered: