litedb group by and order by using SQL select syntax

143 views Asked by At

I am new to litedb and learning as I go. I am trying to use litedb from powershell and the execute method against a DB once connected :

$DN = "c:\test\test.db"
$SQL = "SELECT $ FROM Test"
$LiteDatabase = [LiteDB.LiteDatabase]::new("Filename=$DN;ReadOnly=$true;Connection=Shared")
$Response = $LiteDatabase.Execute($SQL)

This is all working well I want to create an SQL statement now with a GROUP BY and a ORDER BY clause but this is not supported the documentation tells me.

The actual query I would like to run is something like :

select last(*.backupdate) from test group by backupdate order by backupdate

But obviously I cant do the last part

I am hoping there is some clever way to use the "original" way to modify the query to allow for the order by as well - a bit like if you want to group by with more than one field you would use :

{field1: $field1, field2, $field2}

Maybe with sort or orderby but I have tried lots of versions of adding these sorts statements to the SELECT I use with luck :

eg

select sort(last(*.backupdate) => @,'desc') from test group by backupdate

Anyone out there who can help a newbie ?

I wanted to be able to group by and order by in the same statement

0

There are 0 answers