查处列的最大(小)值
时间:2009-07-23 来源:nychenlei
mysql> select article, max(price) as price from shop; 列出最贵的商品
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 19.95 |
+---------+-------+ mysql> select max(price) as price from shop; 列出商品的最高价格
+-------+
| price |
+-------+
| 19.95 |
+-------+ mysql> select article, dealer, price from shop where price=(select max(price) from shop); 列出最贵商品的信息
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0004 | D | 19.95 |
+---------+--------+-------+ mysql> select * from shop order by price desc limit 1;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0004 | D | 19.95 |
+---------+--------+-------+
1 row in set (0.00 sec) mysql> select * from shop order by price limit 1;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0003 | D | 1.25 |
+---------+--------+-------+ 每件商品的最高值和最低值。。 mysql> select article, max(price) as price from shop group by article ;
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 3.99 |
| 0002 | 10.99 |
| 0003 | 1.69 |
| 0004 | 19.95 |
+---------+-------+
4 rows in set (0.00 sec) mysql> select article, min(price) as price from shop group by article ;
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 3.45 |
| 0002 | 10.99 |
| 0003 | 1.25 |
| 0004 | 19.95 |
+---------+-------+
4 rows in set (0.00 sec) mysql> select min(price) as price from shop; 列出商品的最低价格 mysql> select max(createtime) as createtime from user; 列出用户注册的最晚时间。 mysql> select max(lasttime) as lasttime from user_logs; 列出最后一次用户访问的时间。
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 19.95 |
+---------+-------+ mysql> select max(price) as price from shop; 列出商品的最高价格
+-------+
| price |
+-------+
| 19.95 |
+-------+ mysql> select article, dealer, price from shop where price=(select max(price) from shop); 列出最贵商品的信息
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0004 | D | 19.95 |
+---------+--------+-------+ mysql> select * from shop order by price desc limit 1;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0004 | D | 19.95 |
+---------+--------+-------+
1 row in set (0.00 sec) mysql> select * from shop order by price limit 1;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0003 | D | 1.25 |
+---------+--------+-------+ 每件商品的最高值和最低值。。 mysql> select article, max(price) as price from shop group by article ;
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 3.99 |
| 0002 | 10.99 |
| 0003 | 1.69 |
| 0004 | 19.95 |
+---------+-------+
4 rows in set (0.00 sec) mysql> select article, min(price) as price from shop group by article ;
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 3.45 |
| 0002 | 10.99 |
| 0003 | 1.25 |
| 0004 | 19.95 |
+---------+-------+
4 rows in set (0.00 sec) mysql> select min(price) as price from shop; 列出商品的最低价格 mysql> select max(createtime) as createtime from user; 列出用户注册的最晚时间。 mysql> select max(lasttime) as lasttime from user_logs; 列出最后一次用户访问的时间。
相关阅读 更多 +