两种方法:
1. 使用max或者min函数
select max(age),min(age) from user2;
结果:
2. 使用order by 和limit 结合使用
- 取最大值
select age from user2 order by age desc limit 1;
- 取最小值
select age from user2 order by age limit 1;
select max(age),min(age) from user2;
结果:
select age from user2 order by age desc limit 1;
select age from user2 order by age limit 1;