https://en.wikibooks.org/wiki/SQL_Exercises/The_computer_store
两个相连的表格
Manufactures: code, name
products: code, name, price, manufacturer
//黄色是关联。
15. Select the name and price of the cheapest product.
?? :使用嵌套结构,这样能得到所有最便宜的价格的产品,产品价格如果有相同的话。
如果只是写子结构内的代码,只能返回一行。
SELECT Name, Price FROM Products WHERE Price = (SELECT MIN(Price) FROM Products);
16. Select the name of each manufacturer along with the name and price of its most expensive product.不是非常理解;
SELECT A.Name, A.Price, F.Name FROM Products A INNER JOIN Manufacturers F ON A.Manufacturer = F.Code AND A.Price = ( SELECT MAX(A.Price) FROM Products A WHERE A.Manufacturer = F.Code );
原文地址:https://www.cnblogs.com/chentianwei/p/8158005.html
时间: 2024-10-08 23:48:01