I'm trying to port a Postgres query to a sea-queryin Rust. As I'm new to sea-queryI've reached a point where I have no idea how to port the following SQL code:
WITH agg_data AS
(SELECT tableB_fk
, tableB.name
, MAX(version) maxversion
, SUM(downloads) sumdownloads
FROM table1
INNER JOIN tableB on tableB.id = tableA.tableB_fk
GROUP BY tableB.name, tableB_fk)
SELECT ad.*
, t2.created
, t2.downloads
FROM agg_data ad
JOIN tableA t2 ON t2.version = ad.maxversion AND t2.tableB_fk = ad.tableB_fk;
I can't figure out how the query with the with and sub-select is done in sea-query. Unfortunately, there is no example in the docs for the with clause.
Any help is welcome!
The following works and produces the same string as above.