码迷,mamicode.com
首页 > 数据库 > 详细

Sqlite3,维基百科中的练习:

时间:2017-12-31 18:44:39      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:family   tps   man   便宜   san   style   sqli   round   sqlite   

两个相连的表格

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,维基百科中的练习:

标签:family   tps   man   便宜   san   style   sqli   round   sqlite   

原文地址:https://www.cnblogs.com/chentianwei/p/8158005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!