This is  the way to use max function like SQL  to select the max value from the table for Example :

 

 select maxof(PAY_NO) from  ph1 where ph1.ACCOUNT_NO==AccountNo.text()