Query Builder - How to sort by a column alias (aggregate)
Posted: Mon Jan 14, 2019 6:58 pm
Hi
First of all a happy new year to you all, wishing good health, happiness, and many successful Servoy projects
I have the following SQL code and would like to rewrite it as QB Select. But I didn't find an example, docu or hint on how a QB sort is done by an alias like needed in the following SELECT.
The missing piece is how to write the query.sort
Best regards,
First of all a happy new year to you all, wishing good health, happiness, and many successful Servoy projects
I have the following SQL code and would like to rewrite it as QB Select. But I didn't find an example, docu or hint on how a QB sort is done by an alias like needed in the following SELECT.
- Code: Select all
SELECT supplier, MAX(creation_date) as theDate
FROM invoices
GROUP BY supplier
ORDER BY theDate DESC;
The missing piece is how to write the query.sort
- Code: Select all
var query = datasources.db.<name>.invoices.createSelect();
var i = query.columns;
query.result
.add(i.supplier)
.add(i.creation_date.max, 'creationDate');
query.groupBy
.add(i.supplier);
query.sort
.add(???);
Best regards,