Building #11 is undergoing a major renovation. Implement a query to close all requests from apartments in this building.

-- TABLE Apartments

+-------+------------+------------+
| AptID | UnitNumber | BuildingID |
+-------+------------+------------+
| 101 | A1 | 11 |
| 102 | A2 | 12 |
| 103 | A3 | 13 |
| 201 | B1 | 14 |
| 202 | B2 | 15 |
+-------+------------+------------+

-- TABLE Buildings

+------------+-----------+---------------+---------------+
| BuildingID | ComplexID | BuildingName | Address |
+------------+-----------+---------------+---------------+
| 11 | 1 | Eastern Hills | San Diego, CA |
| 12 | 2 | East End | Seattle, WA |
| 13 | 3 | North Park | New York |
| 14 | 4 | South Lake | Orlando, FL |
| 15 | 5 | West Forest | Atlanta, GA |
+------------+-----------+---------------+---------------+

-- TABLE Tenants

+----------+------------+
| TenantID | TenantName |
+----------+------------+
| 1000 | Zhang San |
| 1001 | Li Si |
| 1002 | Wang Wu |
| 1003 | Yang Liu |
+----------+------------+

-- TABLE Complexes

+-----------+---------------+
| ComplexID | ComplexName |
+-----------+---------------+
| 1 | Luxuary World |
| 2 | Paradise |
| 3 | Woderland |
| 4 | Dreamland |
| 5 | LostParis |
+-----------+---------------+

-- TABLE AptTenants

+----------+-------+
| TenantID | AptID |
+----------+-------+
| 1000 | 102 |
| 1001 | 102 |
| 1002 | 101 |
| 1002 | 103 |
| 1002 | 201 |
| 1003 | 202 |
+----------+-------+

-- TABLE Requests

+-----------+--------+-------+-------------+
| RequestID | Status | AptID | Description |
+-----------+--------+-------+-------------+
| 50 | Open | 101 | |
| 60 | Closed | 103 | |
| 70 | Closed | 102 | |
| 80 | Open | 201 | |
| 90 | Open | 202 | |
+-----------+--------+-------+-------------+

这道题让我们更新11号Building,将其所有的Apartment的状态改为Closed,那么我们需要在Requests表中改,该表是状态和Apartment的关系,所以还需要在Apartments表里找和Building的关系,我们用Update和Set关键字来更新Requests表,参见代码如下:

UPDATE Requests SET Status = 'Closed'
WHERE AptID IN
(SELECT AptID FROM Apartments
WHERE BuildingID = 11);

运行结果:

+-----------+--------+-------+-------------+
| RequestID | Status | AptID | Description |
+-----------+--------+-------+-------------+
| 50 | Closed | 101 | |
| 60 | Closed | 103 | |
| 70 | Closed | 102 | |
| 80 | Open | 201 | |
| 90 | Open | 202 | |
+-----------+--------+-------+-------------+

CareerCup All in One 题目汇总

[CareerCup] 15.3 Renting Apartment III 租房之三的更多相关文章

  1. [CareerCup] 15.2 Renting Apartment II 租房之二

    Write a SQL query to get a list of all buildings and the number of open requests (Requests in which ...

  2. [CareerCup] 15.1 Renting Apartment 租房

    Write a SQL query to get a list of tenants who are renting more than one apartment. -- TABLE Apartme ...

  3. [CareerCup] 15.7 Student Grade 学生成绩

    15.7 Imagine a simple database storing information for students' grades. Design what this database m ...

  4. [CareerCup] 15.6 Entity Relationship Diagram 实体关系图

    15.6 Draw an entity-relationship diagram for a database with companies, people, and professionals (p ...

  5. [CareerCup] 15.5 Denormalization 逆规范化

    15.5 What is denormalization? Explain the pros and cons. 逆规范化Denormalization是一种通过添加冗余数据的数据库优化技术,可以帮助 ...

  6. [CareerCup] 15.4 Types of Join 各种交

    15.4 What are the different types of joins? Please explain how they differ and why certain types are ...

  7. [LintCode] House Robber III 打家劫舍之三

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  8. [LeetCode] House Robber III 打家劫舍之三

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  9. [LeetCode] The Maze III 迷宫之三

    There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...

随机推荐

  1. C 和 C++ 混合代码 cmath编译出错

    最近在网上下载了 Triangle 库,准备在程序中调用来三角化生成网格,但出现了很多错误,如下: 1>  triangle.c1>d:\program files\visualstudi ...

  2. 【项目经验】之——Controller向View传值

    我们的ITOO进行了一大部分了,整体上来说还是比较顺利的.昨天进行了一次验收,大体上来说,我们新生这块还是可以的.不仅仅进行了学术上的交流,还进行了需求上的更新.也正是由于这一次,我有了解到了一个新的 ...

  3. 《DSP using MATLAB》示例Example5.3

  4. HTTP基础11--web(3)

    邮件首部注入攻击 指 Web 应用中的邮件发送功能,攻击者通过向邮件首部 To 或 Subject 内任意添加非法内容发起的攻击.利用存在安全漏洞的 Web 网站,可对任意邮件地址发送广告邮件或病毒邮 ...

  5. express-10 表单处理

    从用户那里收集信息的常用方法就是使用HTML表单.无论是使用浏览器提交表单,还是使用AJAX提交,或是运用精巧的前端控件,底层机制通常仍旧是HTML表单. 向服务器发送客户端数据 向服务器发送客户端数 ...

  6. 关于本地存储构成数组以及jquery的inArray方法的使用

    for (var i=0, j = _self.sessionStorage.length; i < j; i++){ var key = _self.sessionStorage.key(i) ...

  7. Spring.Net Remoting 相关使用

    http://www.cnblogs.com/GoodHelper/archive/2009/11/19/SpringNet_Remoting.html  本博客系统转载  原文为 Spring.Se ...

  8. Git pull 强制覆盖本地文件

    git fetch --all git reset --hard origin/master git pull

  9. mac 快捷键大全

    1.control+space 可以使用 spotlight搜索,用于快速找到所需要的文件 2.我尝试使用android studio 提示的快捷键来进行写代码,发现自己按照它的提示操作没有成功,原因 ...

  10. MongoDB 入门之基础 DDL

    此文章主要记录部分主要的 MongoDB 的 DDL 操作. db  查看当前所在的数据库(默认 test) > db test > show dbs  查看当前数据库服务器上的数据库名字 ...