How to 'group by' in foundset

I want to calculate the sum of all orders for each customer in a specified time period.
Right know I’m doing it whit databaseManager.getDataSetByQuery and the following SQL query.

SELECT sum(value) as sumValue, customerID
FROM  orders
WHERE orders.date >= ? and orders.date <= ?
group by customerID

The result of this query is, for each customerID I get a sum of all his orders.
Now I want to convert this to use FoundSetFilterParam, because of compatibly issues (worrying that sum or other SQL functions might not work on other databases)

var _myFs = databaseManager.getFoundSet('myDB','orders')
_myFs.addFoundSetFilterParam('date','>=',_firstLastDateArray[0])
_myFs.addFoundSetFilterParam('date','<=',_firstLastDateArray[1])
_myFs.loadAllRecords()

Also I created an Aggregation sumValue on the orders table.
Whit _myFs.getRecord(1).sumValue I getting the sum of all the orders from all the customers, but I want to have a list from each customer whit his sumValue as I get it whit the SQL script.

Any ideas?
ttmgybta

ttmgybta,

Add an aggregate sum_value = sum(value) to the orders table and create a relation from customers to orders on customerID and globals_order_date_from and globals.order_date_to.
If the date globals dates are set, the expression custrec.customers_to_orders.sum_value will give the result you want.

Using the globals is a bit of a workaround, what would be handy here is to have a relation with arguments so that you don’t have to use globals just to fill in part of your relation.
Something like: custrec.customers_to_orders(date1, date2).sum_value.
That is not possible now, but if people find this idea useful, please file a feature request so we can investigate how much work that is.

Rob

+1!!! :D

+1 too ;-)

+1,

2 weeks ago I said to my Servoy colleague : you know what would be very nice ? parameter support for Servoy relations…

+1 !!!

+5

+1

I could get rid of at least 20 globals used for constants…

+1…I needed this just the other day.

+1

Feature-Request is created in the Servoy Support system!