tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.68k stars 390 forks source link

cte结合窗口函数使用 #1420

Open fuuhoo opened 1 year ago

fuuhoo commented 1 year ago

英文不好,翻译的,不知道你们能看懂了不。。。。 中文来说就是: 如何在tortoise-orm中使用窗口函数和cte的特性进行partition_by等分组查询。

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

i got some problem when i get the first data group by some fields,Ex team using window function and cte

Describe the solution you'd like

this is the example of django and django_cte:

        cte = With(violatAndTrainModel.objects.filter(Q(deleteFlag=0)).annotate(
            rw=models.Window(
                expression=window.RowNumber(),
                partition_by=[models.F('team')],
                order_by=[models.F('time').desc()],
                ),
            ),
        )
        qs0 = cte.queryset().with_cte(cte).filter(rw=1)

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context about the feature request here.