SQLite MIN() 函数
SQLite MIN()
函数用于选择某列的最小值
SELECT MIN(fieldname) FROM tablename;
先运行下面的 SQLite SQL 语句创建测试数据
DROP TABLE tbl_employee; CREATE TABLE tbl_employee ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name CHAR(64) NOT NULL, age INTEGER NOT NULL, city CHAR(64), salary REAL ); INSERT INTO tbl_employee (name,age,city,salary) VALUES ('张三', 25, 'pek', 102400.00 ), ('李四', 18, 'shanghai', 88888.00 ), ('王五', 22, 'hangzhou', 22000.00 ), ('孙六', 32, 'pek', 32000.00 ), ('钱七', 25, 'shanghai', 25000.00 ), ('赵二', 45, 'pek', 45800.00 ), ('冯九', 37, 'chengdu', 15000.00 );
然后运行下面的 SQLite 语句选出 tbl_employee
表 salary
字段的最小值
SELECT MIN(salary) FROM tbl_employee;
输出结果如下
MIN(salary) ----------- 15000.0
可以把 fieldname
替换成任何表达式
SELECT name,age,salary,MIN(salary/age) FROM tbl_employee;
输出结果如下
name age salary MIN(salary/age) ---------- ---------- ---------- ---------------- 冯九 37 15000.0 405.405405405405