Node.js MySQL AVG() Function Last Updated : 07 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report We use AVG Function to get the average value of all rows in the given column of MySQL Table. Syntax: AVG([column_name]) Parameters: AVG() function accepts a single parameter as mentioned above and described below. column_name: Column’s name from which we have to return the average value. Module Installation: Install the mysql module using the following command. npm install mysql Database: Our SQL publishers table preview with sample data is shown below: Example 1: index.js const mysql = require("mysql"); let db_con = mysql.createConnection({ host: "localhost", user: "root", password: '', database: 'gfg_db' }); db_con.on('error', (err) => { console.log(err.code); }); db_con.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err.code); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT AVG(salary) AS avg_salary FROM publishers"; db_con.query(query, (err, rows) => { if(err) throw err; console.log(rows); }); }); Run the index.js file using the following command. node index.jsOutput: Example 2: index.js const mysql = require("mysql"); let db_con = mysql.createConnection({ host: "localhost", user: "root", password: '', database: 'gfg_db' }); db_con.on('error', (err) => { console.log(err.code); }); db_con.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err.code); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT AVG(salary) AS avg_salary FROM publishers WHERE id < 8"; db_con.query(query, (err, rows) => { if(err) throw err; console.log(rows); }); }); Run the index.js file using the following command. node index.jsOutput: Comment More infoAdvertise with us Next Article Node.js MySQL FORMAT() Function P pratikraut0000 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js Technical Scripter 2020 NodeJS-MySQL +1 More Similar Reads Node.js MySQL FORMAT() Function FORMAT() function is a built-in function in MySQL that is used to format input numbers in the format of ...**, ***, *** also, round float numbers to a specific number of decimal places. Syntax: FORMAT(number, number_of_decimal_places)Parameters: It takes two parameters as follows: number: The number 2 min read Node.js MySQL SUM() Function We use the SUM() function in MySQL to get Sum of the value of some columns. Syntax: SUM(column_name) Parameters: SUM() function accepts a single parameter as mentioned above and described below. column_name: Columnâs name from which we have to return the max value. Module Installation: Install the m 2 min read Node.js MySQL Count() Function We use the COUNT() function in MySQL to count a number of rows in a column satisfying the WHERE clause. Syntax: COUNT([column_name]) Parameters: COUNT() function accepts a single parameter as mentioned above and described below. column_name: Columnâs name from which we have to return the count value 2 min read Node.js MySQL Min() Function We will be using Min() function in MySQL to get Minimum value from some particular column. Syntax: MIN(column_name) Parameters: MIN() function accepts a single parameter as mentioned above and described below. column_name: Columnâs name from which we have to return the min value. Return Value: MIN() 2 min read Node.js MySQL FIELD() Function FIELD() function is a built-in function in MySQL that is used to get the position of the first occurrence of a value in a set of expressions. In the case of string values, it is not case-sensitive. Syntax: FIELD(value, input_1, input_2, input_3, ...)Parameters: It takes two parameters as follows: va 2 min read Node.js MySQL MID() Function MID() Function is a Builtin Function in MySQL which is used to get substring of input string between given range inclusive. Syntax: MID(input_string, from, length) Parameters: MID() function accepts three parameters as mentioned above and described below. input_string: Substring of this input will b 2 min read Like