1. 程式人生 > >Sqlite3,維基百科中的練習:

Sqlite3,維基百科中的練習:

ace pri weight 子結構 from blog post hit 1.3

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 );

Sqlite3,維基百科中的練習: