Skip to Content
《Head First SQL》 (Chinese Edition), 2nd Edition
book

《Head First SQL》 (Chinese Edition), 2nd Edition

by Kimberly Fessel
June 2026
740 pages
13h 7m
Chinese
O'Reilly Media, Inc.
Content preview from 《Head First SQL》 (Chinese Edition), 2nd Edition

第 12 章 临时表 短期存储

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

Image

并非所有数据都需要永久保存。到目前为止,您一直将数据表存储在计算机的硬盘上,这意味着即使退出 SQL 或关闭计算机,您仍然可以无限次访问这些数据。但并非所有数据表都需要“一劳永逸。有时您可能只是暂时使用一个数据表,就像一个不讨喜的纹身,您希望它能自行消失。 临时表 正是如此。临时表的行为与普通表完全相同,唯一的区别在于它们 会自动删除 。如果你担心 耗时查询的结果 会消失,或者你的 中间表 占用过多磁盘空间,不妨尝试使用临时表,从而避免这种瞬间的后悔。

炎热难耐

Image

以下是艾比的第一个查询。她的子查询获取了“炎热”天气的ID号。然后,她的外层查询返回了天气ID与“炎热”标识符匹配的地点的城市和国家名称。

查询 #1

SELECT city, country
FROM locations
WHERE weather_id = (SELECT weather_id
                    FROM weather
                    WHERE weather = 'hot');

Abby 的子查询会查找“炎热”天气的 ID 编号。

Image
Image

艾比现在正在检查每个地点的预算需求。与此同时,她的代码大部分保持不变,但她不得不重新输入所有内容。

查询 #2

Image
city country 预算
罗马 意大利 3000
马拉喀什 摩洛哥 2000
迪拜 阿联酋 3000
迈阿密 美国 3000
Image

现在艾比需要travel_hourstravel_mode这两个列,但她仍需再次编写完整的查询语句来查找“热门”地点。

查询 #3

Image

这个主意不错。我们来试试看。

请记住,您可以 从任何查询结果中创建新表 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Overcome a Power Deficit

How to Overcome a Power Deficit

Cyril Bouquet, Jean-Louis Barsoux
Relational Power Is the New Currency of Hybrid Work

Relational Power Is the New Currency of Hybrid Work

Lebene Soga, Yemisi Bolade-Ogunfodun, Nazrul Islam, Joseph Amankwah-Amoah

Publisher Resources

ISBN: 0642572408114