Return max value in a column with peewee
Asked Answered
T

1

6

I have a table called jobs with a column called job_num. How do i return the maximum value of the integers in that column?

I have tried

result = Job.select(max(Job.job_num))

I have also tried a few different combinations such as

result = Job.select(Job.job_num).max()

I have also checked the peewee docs. Can anyone help please.

Tears answered 20/3, 2018 at 22:49 Comment(0)
G
15

You can use "fn.MAX" to apply the SQL MAX function. The "scalar()" method returns a single, scalar result value:

result = Job.select(fn.MAX(Job.job_num)).scalar()
Gev answered 22/3, 2018 at 13:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.