user image

AKY King of Life
Published in : 2022-03-05

Select from a query with peewee


have some troubles implementing the following query with peewee:

SELECT *FROM ( SELECT datas.*, (rank() over(partition by tracking_id order by date_of_data DESC)) as rank_result FROM datas WHERE tracking_id in (1, 2, 3, 4, 5, 6))WHERE rank_result < 3;

I have tried to do the following:

subquery = (, Datas.value, Datas.date_of_data, fn.rank().over(partition_by=[Datas.tracking], order_by=[Datas.date_of_data.desc()]).alias('rank')) .where(Datas.tracking.in_([1, 2, 3, 4, 5, 6])))result = ( .from_(subquery) .where(SQL('rank') < 3))

but since I'm doing "" i'm getting all the fields in the SQL SELECT which i don't want and which doesn't make my query work. Here is the schema of my table:

CREATE TABLE IF NOT EXISTS "datas" ( "id" INTEGER NOT NULL PRIMARY KEY, "tracking_id" INTEGER NOT NULL, "value" INTEGER NOT NULL, "date_of_data" DATETIME NOT NULL, FOREIGN KEY ("tracking_id") REFERENCES "follower" ("id"));CREATE INDEX "datas_tracking_id" ON "datas" ("tracking_id");



There is no comments yet

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Is there any port I need to allow in google VM instances to allow SMTP?
Publish date: 2022-02-14 | Comments: 1

Tag: General

Password authentication is temporarily disabled as part of a brownout.
Publish date: 2021-07-28 | Comments: 2

Tag: General

Where can I find cheap Java and Mysql hosting server?
Publish date: 2022-05-03 | Comments: 3

Tag: General

Searching for free live chat service
Publish date: 2022-02-11 | Comments: 2

Tag: General

Choose default editor from filezilla on Ubuntu
Publish date: 2022-02-28 | Comments: 4

Tag: General

what is alternative for sending mail through Gmail SMTP?
Publish date: 2022-06-08 | Comments: 3

Tag: General

Help with sliding an image from the top of a stack
Publish date: 2022-02-12 | Comments: 1

Tag: General