[Python] Query by row_number() in Sqlalchemy

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a query in raw SQL

    select * from (select ROW_NUMBER() over(partition by
    "categoryId" order by "updatedAt" desc) as "RowNum",
    "categoryId", "updatedAt" from products as tdr) a
    where "RowNum"=1


    How can I perform the same query in Flask Sqlalchemy?

    I tried different approaches, and found a better solutions in Miguelgrinberg's Cookbook

    Continue reading...

Compartilhe esta Página