[CareerCup] 15.3 Renting Apartment III 租房之三
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] 15.3 Renting Apartment III 租房之三的更多相关文章
- [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 ...
- [CareerCup] 15.1 Renting Apartment 租房
Write a SQL query to get a list of tenants who are renting more than one apartment. -- TABLE Apartme ...
- [CareerCup] 15.7 Student Grade 学生成绩
15.7 Imagine a simple database storing information for students' grades. Design what this database m ...
- [CareerCup] 15.6 Entity Relationship Diagram 实体关系图
15.6 Draw an entity-relationship diagram for a database with companies, people, and professionals (p ...
- [CareerCup] 15.5 Denormalization 逆规范化
15.5 What is denormalization? Explain the pros and cons. 逆规范化Denormalization是一种通过添加冗余数据的数据库优化技术,可以帮助 ...
- [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 ...
- [LintCode] House Robber III 打家劫舍之三
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- [LeetCode] House Robber III 打家劫舍之三
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- [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 ...
随机推荐
- Dwz下拉菜单的二级联动
在DWZ文档中对组合框combox的是这样描述的: 在传统的select 用class 定义:class=”combox”, html 扩展:保留原有属性name, 增加了属性:ref. ref 属 ...
- 在Salesforce中添加Workflow Rule
在Salesforce中可以添加Workflow Rule来执行特定的动作,比如说:当Object的某个字段发生变化时,根据变化的值去修改其他field,和Trigger的功能很类似,不过Trigge ...
- 在Salesforce中实现对Object的增删改查操作
1): Insert Statement http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=ap ...
- customTextbox
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- ios 数据类型转换 UIImage转换为NSData NSData转换为NSString
1.UIImage转换为NSData NSData *data;if (UIImagePNGRepresentation(image) == nil) { data = UIImageJPEGRepr ...
- 利用myeclipse配置数据库连接池
作为一个习惯使用myeclipse的人来说,即使是数据库连接池也肯定是用ide配置了. 下面说一下用数据库连接池的配置. 1 创建工程.不多说了. 2 添加数据库连接程序驱动包.直接放到lib目录下即 ...
- Http协议提要
HTTP协议提要 简单来说,HTTP就是一个基于应用层的通信规范:双方要进行通信,大家就要遵守一个规范---HTTP协议.HTTP协议从WWW服务器超文本到本地浏览器 ,可以使浏览器更加高效.HTTP ...
- Java数组课后作业
1.运行TestArrays.java,了解Arrays中的一些重要方法的用法. Arrays.equals(a 1, a2):判断数组是否相等. int[] b = Arrays.copyOf(a, ...
- 17996 Daily Cool Run (dp)
时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: 不限定 Description Daily Cool Run is a popular gam ...
- Java NIO示例:多人网络聊天室
一个多客户端聊天室,支持多客户端聊天,有如下功能: 功能1: 客户端通过Java NIO连接到服务端,支持多客户端的连接 功能2:客户端初次连接时,服务端提示输入昵称,如果昵称已经有人使用,提示重新输 ...