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.

Finchy70
  • 441
  • 9
  • 25

1 Answers1

13

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()
coleifer
  • 24,887
  • 6
  • 60
  • 75