How to use the max function from knex
Find comprehensive JavaScript knex.max code examples handpicked from public code repositorys.
knex.max is a function that generates a MAX aggregate query in SQL to retrieve the maximum value of a specific column in a table.
43 44 45 46 47 48 49 50 51 52
// .select(knex.ref('login').as('name')) // .from('users'); //const data = await knex.sum('age').from('users2'); //const data = await knex.avg('age').from('users2'); //const data = await knex.max('age').from('users2'); //const data = await knex.min('age').from('users2'); // const data = await knex.avg('sum_age').from(function () { // this.sum('age as sum_age').from('users2').groupBy('name').as('t1');
0
0
1
+ 2 other calls in file
How does knex.max work?
knex.max is a function that returns a new instance of the QueryBuilder class that constructs a SELECT query with a MAX function to get the maximum value of a specified column in a table. The MAX function is used in the SQL query to return the highest value of a specific column, as specified by the user. The knex.max function takes one argument, which is the name of the column for which the maximum value is to be retrieved.
Ai Example
1 2
const maxAge = await knex("users").max("age"); console.log(maxAge); // Outputs { 'max(`age`)': 50 }