Node.js MySQL Count() Function Last Updated : 07 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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. 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: Count publishers having id greater than 5 index.js const mysql = require("mysql"); let db_con = mysql.createConnection({ host: "localhost", user: "root", password: '', database: 'gfg_db' }); db_con.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT COUNT(id) AS id_count FROM publishers WHERE id > 5"; 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.connect((err) => { if (err) { console.log("Database Connection Failed !!!", err); return; } console.log("We are connected to gfg_db database"); // Here is the query let query = "SELECT COUNT(salary) AS salary_count FROM publishers WHERE salary BETWEEN 5000 AND 10000"; 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 CONCAT_WS() Function CONCAT_WS() function is a built-in function in MySQL that is used to concatenate a set of strings with a commonly given separator. Syntax: CONCAT_WS(separator, string_1, string_2, ...)Parameters: It takes two parameters as follows: separator: This separator will be used to concatenate strings.string 2 min read 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 AVG() Function 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 Inst 2 min read D3.js node.count() Function The node.count() function of D3.js library is used to count the number of leaves under a particular node and append it as a value property to the object. If the node given is itself a leaf node then the count is one. Syntax: node.count(); Parameters: This function does not take any parameter. Return 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 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 Like