tortoise / tortoise/tortoise-orm

cte结合窗口函数使用

Open
#1,420 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

英文不好,翻译的,不知道你们能看懂了不。。。。
中文来说就是:
如何在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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the requested Django/django_cte example with Tortoise ORM's existing query capabilities. Investigate how window functions, partition_by, and CTEs are currently represented, then define completion as enabling the described first-row-per-team query in Tortoise ORM.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.