您的位置:首页 > 其它

计算最大价格。。。

2015-05-18 10:49 141 查看
准备的表与数据:

mysql> desc shop ;

+---------+-------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+-------------+------+-----+---------+-------+

| article | varchar(20) | YES | | NULL | |

| dealer | char(1) | YES | | NULL | |

| price | double | YES | | NULL | |

+---------+-------------+------+-----+---------+-------+

mysql> select * from shop;

+---------+--------+-------+

| article | dealer | price |

+---------+--------+-------+

| 0001 | D | 20.5 |

| 0002 | C | 11.5 |

| 0003 | F | 81.5 |

+---------+--------+-------+

方式1:

mysql> select s1.* from shop s1 left join shop s2 on s1.price <s2.price where s2.article is null;

+---------+--------+-------+

| article | dealer | price |

+---------+--------+-------+

| 0003 | F | 81.5 |

+---------+--------+-------+

方式2:

mysql> select * from shop s1 where price = (select max(price) from shop s2);

+---------+--------+-------+

| article | dealer | price |

+---------+--------+-------+

| 0003 | F | 81.5 |

+---------+--------+-------+

方式3:

mysql> select * from shop order by price desc limit 1;

+---------+--------+-------+

| article | dealer | price |

+---------+--------+-------+

| 0003 | F | 81.5 |

+---------+--------+-------+
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐