'Return max value in a column with peewee
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.
Solution 1:[1]
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | coleifer |