我們將在MySQL中使用Min()函數從某些特定列獲取最小值。
用法:
MIN(column_name)
參數:MIN()函數接受如上所述和以下描述的單個參數。
- column_name:我們必須從中返回最小值的列名。
返回值:MIN()函數從表中的特定列返回最小值。
模塊安裝:使用以下命令安裝MySQL模塊。
npm install mysql
數據庫:下麵顯示了我們的SQL Publishers表預覽以及示例數據。
範例1:
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 MIN(salary) AS min_salary FROM publishers";
db_con.query(query, (err, rows) => {
if(err) throw err;
console.log(rows);
});
});
輸出:
範例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 MIN(salary) AS min_salary
FROM publishers WHERE id < 7";
db_con.query(query, (err, rows) => {
if(err) throw err;
console.log(rows);
});
});
輸出:
相關用法
- Node.js MySQL Max()用法及代碼示例
- Node.js GM solarize()用法及代碼示例
- Node.js process.nextTick()用法及代碼示例
- PHP min( )用法及代碼示例
- d3.js d3.min()用法及代碼示例
- p5.js min()用法及代碼示例
- Tensorflow.js tf.min()用法及代碼示例
- underscore.js _.min用法及代碼示例
- MySQL FIELD()用法及代碼示例
- MySQL CHARACTER_LENGTH()用法及代碼示例
- MySQL PERIOD_ADD()用法及代碼示例
- MySQL CONCAT_WS()用法及代碼示例
- MySQL SYSTEM_USER()用法及代碼示例
- MySQL FORMAT()用法及代碼示例
- MySQL INSTR()用法及代碼示例
- MySQL GET_FORMAT()用法及代碼示例
注:本文由純淨天空篩選整理自pratikraut0000大神的英文原創作品 Node.js MySQL Min() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。