High School Computer Science

Data, Databases and the Web数据、数据库与网络

Every modern program stores, retrieves, and transmits data. This guide builds the complete picture: what data (data) and information (information) are and how they differ; how to read and write files (file) on disk; how comma-separated values (CSV) let programs share structured data; how relational databases (relational database) organise information into tables (table) linked by keys; how SQL queries (query) let you ask questions of a database with SELECT and WHERE; how HTML assembles a web page (web page); and how web APIs expose data in JSON format so programs can talk to each other over the internet. Code and SQL examples are shown in <pre><code> blocks with Chinese explanations alongside.每个现代程序都需要存储、检索和传输数据(data,数据)。本指南构建完整图景:数据(data,数据)与信息(information,信息)是什么、有何区别;如何从磁盘读写文件(file,文件);逗号分隔值(CSV)如何让程序共享结构化数据;关系数据库(relational database,关系数据库)如何将信息组织成通过键连接的表(table,表);SQL 查询(query,查询)如何通过 SELECT 和 WHERE 向数据库提问;HTML 如何组合网页(web page,网页);以及网络接口(API,接口)如何以 JSON 格式暴露数据,使程序能通过互联网相互通信。

7 sections7 节内容 US CSTA · AP CSP · ON · BC · ABUS CSTA · AP CSP · ON · BC · AB Python + SQL + HTML code examplesPython + SQL + HTML 代码示例

How to use this guide如何使用本指南

Data and databases are treated as a core topic by the US frameworks (CSTA 3A-DA family; AP CSP Big Idea 2 at 17–22% of the exam). Ontario takes a split approach: file I/O sits in ICS4U (university stream, Grade 12), while SQL and web work sit in ICS4C (college stream). BC covers data mainly in the big-data/privacy and Internet-evolution framing of CIS 11/12, with no dedicated SQL standard. Alberta covers files thoroughly in CSE2130 and has a full web-scripting pathway (CSE1210 to CSE3210), but no SQL module in the CSE cluster. Sections §1–§3 (data, files, CSV) are universal. Sections §4–§5 (relational databases, SQL) map most directly to US CSTA, AP CSP, and ON ICS4C. Sections §6–§7 (HTML, JSON/APIs) align with Alberta web scripting and AP CSP Big Idea 2.美国框架将数据和数据库视为核心主题(CSTA 3A-DA 系列;AP CSP 大概念 2 占考试 17–22%)。安大略采用分流方式:文件读写在 ICS4U(大学预科,12 年级),SQL 和网页工作在 ICS4C(学院预科)。BC 主要在 CIS 11/12 的大数据/隐私和互联网演变框架中涵盖数据,没有专用 SQL 标准。阿尔伯塔在 CSE2130 中详细涵盖文件,并有完整的网页脚本路径(CSE1210 至 CSE3210),但 CSE 群集中没有 SQL 模块。§1–§3(数据、文件、CSV)是通用的。§4–§5(关系数据库、SQL)最直接对应美国 CSTA、AP CSP 和安大略 ICS4C。§6–§7(HTML、JSON/接口)与阿尔伯塔网页脚本和 AP CSP 大概念 2 对齐。

If you are in…如果你在… Focus on these sections重点学习 Defer / lighter可推迟 / 减负 Source依据
🇺🇸 US CSTA / AP CSP美国 CSTA / AP CSP §1 through §7 in full. CSTA 3A-DA-10/11/12 cover data organisation, visualisation and models. AP CSP Big Idea 2 (DAT) topics 2.3 and 2.4 test extracting information from data and using programs with data.§1 至 §7 完整学习。CSTA 3A-DA-10/11/12 涵盖数据组织、可视化和模型。AP CSP 大概念 2(DAT)主题 2.3 和 2.4 考查从数据中提取信息以及将程序与数据结合使用。 Nothing — AP CSP Big Idea 2 (17–22% of exam) makes all seven sections core for AP students.无——AP CSP 大概念 2(占考试 17–22%)使所有七节对 AP 学生都是核心。 CSTA K-12 and AP CSP — CSTA 3A-DA-10, 3A-DA-11, 3A-DA-12; AP CSP Big Idea 2 (DAT) topics 2.3, 2.4— CSTA 3A-DA-10、3A-DA-11、3A-DA-12;AP CSP 大概念 2(DAT)主题 2.3、2.4
🇨🇦 ON — ICS4U (Grade 12 Univ.)安大略 — ICS4U(12 年级大学预科) §1–§3 (data, file I/O, CSV) map directly to ICS4U A3.1. The file I/O worked examples in §2 are the exact skill assessed. §6 (HTML) for context only.§1–§3(数据、文件读写、CSV)直接对应 ICS4U A3.1。§2 的文件读写例题是被考查的确切技能。§6(HTML)仅作背景。 §4–§5 (relational databases, SQL) are ICS4C college-stream content — skip for ICS4U floor.§4–§5(关系数据库、SQL)是 ICS4C 学院流内容——ICS4U 基础学生可跳过。 ON/BC Computer Studies 11-12 — ICS4U A3.1 (file I/O); ICS4C A2.2 (SQL)— ICS4U A3.1(文件读写);ICS4C A2.2(SQL)
🇨🇦 BC — CIS 11 / CIS 12BC — CIS 11 / CIS 12 §1 (data vs information), §6 (HTML), §7 (JSON/APIs). CIS 11 covers Internet evolution; CIS 12 covers global shifts from online access. File I/O and SQL are enrichment for BC students.§1(数据与信息)、§6(HTML)、§7(JSON/接口)。CIS 11 涵盖互联网演变;CIS 12 涵盖在线访问带来的全球变革。文件读写和 SQL 对 BC 学生为拓展内容。 BC has no relational-database/SQL standard — §4–§5 are enrichment, not assessed.BC 没有关系数据库/SQL 标准——§4–§5 为拓展内容,不被考查。 ON/BC Computer Studies 11-12 — BC CS10 big-data/IoT Content; CIS11/12 Internet/online Content bullets— BC CS10 大数据/物联网内容;CIS11/12 互联网/在线内容条目
🇨🇦 AB — CSE2130 / Web Pathway阿尔伯塔 — CSE2130 / 网页路径 §1–§3 (data, file I/O) align with CSE2130 outcomes. §6 (HTML) maps to CSE1210/1220 client-side scripting. §7 (JSON/APIs) maps to CSE2210/3210.§1–§3(数据、文件读写)与 CSE2130 结果对齐。§6(HTML)对应 CSE1210/1220 客户端脚本。§7(JSON/接口)对应 CSE2210/3210。 §4–§5 (relational databases, SQL) — no SQL module in the CSE cluster; treat as enrichment.§4–§5(关系数据库、SQL)——CSE 群集中没有 SQL 模块;作为拓展内容。 Alberta CTS Computing Science — CSE2130 outcomes 1.4.2, 1.4.5, 1.4.6; CSE1210/1220 descriptions— CSE2130 结果 1.4.2、1.4.5、1.4.6;CSE1210/1220 描述

Once you have located your row, use the two cards below for the speed at which you should work through the recommended sections.找到所在行后,用下面两张卡片决定推进速度。

!
If you are cramming the night before如果你在临阵磨枪

Memorise three things: the difference between data and information; how to open, read, and write a file in Python; and what SELECT/WHERE does in SQL. Read every cram-cheat box. For AP CSP, know that Big Idea 2 tests how programs extract knowledge from data — JSON, CSV, and database queries are all fair game.背熟三件事:数据与信息的区别;如何在 Python 中打开、读取和写入文件;SQL 中 SELECT/WHERE 的作用。读每个速记框。对于 AP CSP,要知道大概念 2 考查程序如何从数据中提取知识——JSON、CSV 和数据库查询都可能考到。

*
If you are going for the top mark如果你目标顶分

Work through all seven sections in order. The sections build: data → files → CSV → relational tables → SQL → HTML → JSON/APIs. Each concept assumes the previous. For AP CSP, be able to write a program that reads a CSV, filters rows, and outputs a result — that is the synthesis of §2, §3, and §5 combined. For CSTA 3A-DA-11, be able to describe how you would visualise the data you just queried.按顺序学习全部七节。各节层层递进:数据 → 文件 → CSV → 关系表 → SQL → HTML → JSON/接口。每个概念都以前一个为基础。对于 AP CSP,能够编写读取 CSV、过滤行并输出结果的程序——这是 §2、§3 和 §5 的综合。对于 CSTA 3A-DA-11,能够描述如何可视化刚刚查询到的数据。


Data vs Information数据与信息

Two definitions to lock in first.先锁定两个定义。
  • Data数据 — raw, unprocessed facts and symbols. Examples: 98.6, "Alice", true, a pixel value. Data has no inherent meaning on its own.— 原始、未经处理的事实和符号。例如:98.6"Alice"true、一个像素值。数据本身没有固有含义。
  • Information信息 — data that has been processed, organised, or interpreted so it carries meaning. Example: "Alice's body temperature is 98.6°F, which is normal." Context turns data into information.— 经过处理、组织或解释后具有含义的数据。例如:"Alice 的体温是 98.6°F,属于正常。"上下文将数据转变为信息。
  • Data types数据类型 — integer, float, string, Boolean, list. Every value stored in a program belongs to a type. CSTA 3A-DA-10: "Evaluate the tradeoffs in how data elements are organized and where data is stored."— 整数、浮点数、字符串、布尔值、列表。程序中存储的每个值都属于一种类型。CSTA 3A-DA-10:"评估数据元素的组织方式和存储位置的权衡。"
The AP CSP angle: Big Idea 2 (DAT) opens with "Data are central to computing innovations because they communicate initial conditions to programs and represent new knowledge." (AP CSP CED, verbatim). The whole Big Idea is built on the data → information pipeline this section introduces.AP CSP 视角:大概念 2(DAT)以"数据是计算创新的核心,因为它们向程序传递初始条件并代表新知识"开篇(AP CSP CED 原文)。整个大概念建立在本节介绍的数据 → 信息管线之上。
WE
Worked Example 1 · From sensor readings to a weather report例题 1 · 从传感器读数到天气报告

A weather station collects three sensor readings every minute: temperature, humidity, pressure. Show the data → information transformation.气象站每分钟采集三个传感器读数:温度、湿度、气压。展示数据 → 信息转换过程。

Raw data (numbers, no meaning without context).原始数据(数字,脱离上下文没有含义)。

22.4, 65, 1013.2
22.6, 64, 1013.0
22.9, 63, 1012.7

The three columns are temperature (°C), humidity (%), and pressure (hPa) — but without column headers these numbers carry no meaning.三列分别是温度(°C)、湿度(%)、气压(hPa)——但如果没有列标题,这些数字毫无意义。

Processing step: label, aggregate, interpret.处理步骤:标注、聚合、解释。

# Python: compute average temperature from a list of readings
readings = [22.4, 22.6, 22.9]
avg_temp = sum(readings) / len(readings)
print(f"Average temperature: {avg_temp:.1f} °C")
# Output: Average temperature: 22.6 °C

sum(readings) adds all values; len(readings) returns the list length; f"..." is a formatted string literal (f-string).sum(readings) 求和,len(readings) 取列表长度,f"..." 是格式化字符串。

Information.信息。 "Average temperature over the last 3 minutes: 22.6 °C. Trend: rising. Humidity dropping. Pressure falling slowly — possible rain within 6 hours." The same raw numbers now carry actionable meaning. CSTA 3A-DA-12: "Create computational models that represent the relationships among different elements of data collected from a phenomenon or process.""过去 3 分钟平均温度:22.6 °C。趋势:上升。湿度下降。气压缓慢下降——6 小时内可能有雨。"同样的原始数字现在具有了可行动的含义。CSTA 3A-DA-12:"创建计算模型,表示从现象或过程中收集的数据的不同元素之间的关系。"

A spreadsheet contains the values 87, 92, 74, 95 with no labels. Which best describes these values?一张电子表格包含值 87, 92, 74, 95,没有标签。哪个最能描述这些值?
§1 · Q1
Information, because they are numbers信息,因为它们是数字
Information, because a computer can read them信息,因为计算机可以读取它们
Data, because they have no context or meaning数据,因为它们没有上下文或含义
Neither data nor information既不是数据也不是信息
Without labels, we do not know if these are test scores, temperatures, or IDs. Raw values with no context are data, not information. Only after labelling and interpreting (e.g., "these are exam scores; average = 87") do they become information.没有标签,我们不知道这些是考试成绩、温度还是 ID。没有上下文的原始值是数据,而非信息。只有在标注和解释后(如"这些是考试成绩;平均分 = 87"),它们才成为信息。
Being a number or being computer-readable does not make something information. Information requires context and meaning. Raw unlabelled values are data.是数字或可被计算机读取并不使某物成为信息。信息需要上下文和含义。未标注的原始值是数据。
CSTA standard 3A-DA-10 says "Evaluate the tradeoffs in how data elements are organized and where data is stored." Which choice is an example of such a tradeoff?CSTA 标准 3A-DA-10 说"评估数据元素组织方式和数据存储位置的权衡"。哪个选项是这种权衡的例子?
§1 · Q2
Choosing between Python and Java在 Python 和 Java 之间选择
Deciding whether to use a loop or recursion决定使用循环还是递归
Selecting a font for a report为报告选择字体
Storing student records in a flat CSV vs a relational database — CSV is simpler but harder to query across tables将学生记录存储为平面 CSV 与关系数据库——CSV 更简单但跨表查询更难
3A-DA-10 is about data organisation and storage decisions. Choosing between a flat file (CSV) and a relational database is a classic data-storage tradeoff: CSV is simple and portable but lacks relational querying power; a database is complex to set up but powerful to query.3A-DA-10 关于数据组织和存储决策。在平面文件(CSV)和关系数据库之间选择是经典的数据存储权衡:CSV 简单且可移植,但缺乏关系查询能力;数据库设置复杂,但查询功能强大。
Language choice, loop vs recursion, and fonts are not data organisation tradeoffs. The tradeoff CSTA 3A-DA-10 asks about is how and where to store data — e.g., CSV vs database.语言选择、循环与递归、字体都不是数据组织权衡。CSTA 3A-DA-10 问的权衡是如何以及在哪里存储数据——例如 CSV 与数据库。

File Input/Output (Reading and Writing Files)文件输入/输出(读写文件)

Three file operations to memorise.需要记住的三个文件操作。
  • Open打开 — connect a program to a file on disk. Modes: "r" read, "w" write (overwrites), "a" append. CSE2130 outcome 1.4.2: "opening an existing file."— 将程序连接到磁盘上的文件。模式:"r" 读取,"w" 写入(覆盖),"a" 追加。CSE2130 结果 1.4.2:"打开现有文件。"
  • Read / Write读取 / 写入 — transfer data between the program and the file. Read brings data in; write sends data out. CSE2130 outcomes 1.4.5 "importing data from a file" and 1.4.4 "exporting data to a file."— 在程序和文件之间传输数据。读取将数据带入;写入将数据送出。CSE2130 结果 1.4.5"从文件导入数据"和 1.4.4"将数据导出到文件"。
  • Close关闭 — flush and disconnect. In Python, use with open(...) as f: — the file closes automatically when the block exits. Always close files to avoid data loss.— 刷新并断开连接。在 Python 中,使用 with open(...) as f:——代码块退出时文件自动关闭。始终关闭文件以避免数据丢失。
Ontario ICS4U A3.1 (verbatim): "demonstrate the ability to read from, and write to, an external file (e.g., text file, binary file, database, XML file) from within a computer program."安大略 ICS4U A3.1(原文):"展示从计算机程序内部读写外部文件(如文本文件、二进制文件、数据库、XML 文件)的能力。"
WE
Worked Example 2 · Reading a text file and writing a summary例题 2 · 读取文本文件并写入摘要

File scores.txt contains one integer per line. Read all scores, compute the average, and write the result to summary.txt.文件 scores.txt 每行包含一个整数。读取所有成绩,计算平均值,并将结果写入 summary.txt

scores.txt (sample content).scores.txt(示例内容)。

87
92
74
95
88

Python: read, process, write.Python:读取、处理、写入。

# Read all scores from file
with open("scores.txt", "r") as f:
    scores = [int(line.strip()) for line in f]

# Process: compute average
average = sum(scores) / len(scores)

# Write summary to a new file
with open("summary.txt", "w") as f:
    f.write(f"Count: {len(scores)}\n")
    f.write(f"Average: {average:.1f}\n")

print("Done. summary.txt written.")

open("scores.txt", "r") opens the file in read-only mode; line.strip() removes the trailing newline; int(...) converts the string to an integer; open("summary.txt", "w") creates or overwrites the file in write mode; f.write(...) writes content; \n is the newline character.open("scores.txt", "r") 以只读模式("r",read)打开文件;line.strip() 去除换行符;int(...) 将字符串转为整数;open("summary.txt", "w") 以写入模式("w",write)创建/覆盖文件;f.write(...) 写入内容;\n 是换行符。

Output in summary.txt.summary.txt 中的输出。

Count: 5
Average: 87.2
In Python, which mode string opens a file for appending (adding to the end without erasing existing content)?在 Python 中,哪个模式字符串以追加方式打开文件(在末尾添加内容而不删除现有内容)?
§2 · Q1
"r"
"a"
"w"
"x"
"a" is append mode — it opens the file and positions the write cursor at the end, so new data is added after existing content. "r" = read only, "w" = write (overwrites everything), "x" = create new file (fails if file exists)."a" 是追加模式——打开文件并将写入游标定位在末尾,因此新数据添加到现有内容之后。"r" = 只读,"w" = 写入(覆盖所有内容),"x" = 创建新文件(文件已存在则失败)。
File modes: "r" read, "w" write/overwrite, "a" append, "x" exclusive create. Appending means adding to the end without erasing — that is "a".文件模式:"r" 读取,"w" 写入/覆盖,"a" 追加,"x" 独占创建。追加意味着在末尾添加而不删除——那就是 "a"
Why does Python's with open(...) as f: pattern eliminate the need to call f.close()?为什么 Python 的 with open(...) as f: 模式不需要调用 f.close()
§2 · Q2
The with block automatically closes the file when the block exits, even if an error occurswith 块在代码块退出时自动关闭文件,即使发生错误也是如此
Python never needs files to be closedPython 从不需要关闭文件
The as f clause closes the file when f is reassignedas f 子句在 f 被重新赋值时关闭文件
Only write-mode files need to be closed只有写入模式的文件需要关闭
The with statement is a context manager. When execution leaves the with block — normally or via an exception — Python calls the file's __exit__ method, which flushes and closes the file. This guarantees no data is lost even if an error occurs mid-write.with 语句是一个上下文管理器。当执行离开 with 块时——正常退出或通过异常——Python 调用文件的 __exit__ 方法,该方法刷新并关闭文件。这保证即使写入过程中发生错误,数据也不会丢失。
Files should always be closed to flush buffers and release the OS file handle. The with block handles this automatically via Python's context manager protocol.文件应始终关闭以刷新缓冲区并释放操作系统文件句柄。with 块通过 Python 的上下文管理器协议自动处理这一点。

CSV and Structured DataCSV 与结构化数据

CSV in three facts.CSV 的三个要点。
  • CSV = Comma-Separated ValuesCSV = 逗号分隔值 — a plain-text format where each line is a record and fields within a line are separated by commas. The first line is usually a header row naming each column.— 一种纯文本格式,每行是一条记录,行内字段用逗号分隔。第一行通常是命名每列的标题行。
  • Universal exchange format通用交换格式 — spreadsheets, databases, and programs all export/import CSV. It is the most common format for sharing tabular data between systems. CSTA 3A-DA-11 says to "create interactive data visualisations" — CSV is how you get the data in.— 电子表格、数据库和程序都可以导出/导入 CSV。它是系统间共享表格数据最常见的格式。CSTA 3A-DA-11 要求"创建互动数据可视化"——CSV 就是数据的来源方式。
  • Python's csv modulePython 的 csv 模块 csv.reader parses each row into a list; csv.DictReader maps each row to a dictionary keyed by column name. Always prefer DictReader for named columns.csv.reader 将每行解析为列表;csv.DictReader 将每行映射为以列名为键的字典。对于有名列,始终优先使用 DictReader
WE
Worked Example 3 · Reading a CSV of student records例题 3 · 读取学生记录的 CSV

File students.csv stores name, grade, and score. Read it and print students who scored above 85.文件 students.csv 存储姓名、年级和成绩。读取它并打印成绩高于 85 的学生。

students.csv content.students.csv 内容。

name,grade,score
Alice,11,92
Bob,11,78
Carol,12,95
David,12,82
Eve,11,88

Python: filter rows where score > 85.Python:过滤成绩 > 85 的行。

import csv

with open("students.csv", "r") as f:
    reader = csv.DictReader(f)
    for row in reader:
        if int(row["score"]) > 85:
            print(row["name"], row["score"])

# Output:
# Alice 92
# Carol 95
# Eve 88

import csv loads the built-in csv module; csv.DictReader(f) reads each row as a dictionary (e.g. {"name": "Alice", "grade": "11", "score": "92"}); int(row["score"]) converts the string to an integer before comparing; row["name"] accesses a field by column name.import csv 导入内置 csv 模块;csv.DictReader(f) 将每行读为字典({"name": "Alice", "grade": "11", "score": "92"});int(row["score"]) 将字符串转为整数后比较;row["name"] 通过列名访问字段。

In a CSV file, the first row is name,grade,score. What is this row called?在 CSV 文件中,第一行是 name,grade,score。这一行叫什么?
§3 · Q1
A record记录
A field字段
A header row标题行
A delimiter分隔符
The first row of a CSV is the header row — it names each column. Every subsequent row is a record (one row of data). Each item within a row is a field. The comma is the delimiter (separator character).CSV 的第一行是标题行——它命名每列。之后的每行是一条记录(一行数据)。行内每项是一个字段。逗号是分隔符(分隔字符)。
Header row = first row naming columns. Record = a subsequent data row. Field = one value within a row. Delimiter = the comma separator character.标题行 = 命名列的第一行。记录 = 后续数据行。字段 = 行内一个值。分隔符 = 逗号分隔字符。
A program reads a CSV where all values are strings. To compare the score field to 85 numerically, what must you do first?程序读取一个 CSV,所有值都是字符串。要将 score 字段与 85 进行数值比较,必须先做什么?
§3 · Q2
Nothing — Python compares strings and integers automatically什么都不用做——Python 自动比较字符串和整数
Convert the string to an integer using int(row["score"])使用 int(row["score"]) 将字符串转换为整数
Convert 85 to a string using str(85)使用 str(85) 将 85 转换为字符串
Use double equals: row["score"] == 85使用双等号:row["score"] == 85
CSV values are always read as strings. Comparing "92" > 85 would raise a TypeError in Python 3 (or give wrong results in Python 2). You must first convert: int(row["score"]) > 85. This is the most common bug when processing CSV data.CSV 值始终作为字符串读取。在 Python 3 中,比较 "92" > 85 会引发 TypeError(在 Python 2 中会给出错误结果)。必须先转换:int(row["score"]) > 85。这是处理 CSV 数据时最常见的错误。
Python 3 raises a TypeError if you compare a string to an integer with >. CSV fields are always strings — convert them first with int() or float() before numeric comparison.Python 3 中用 > 比较字符串和整数会引发 TypeError。CSV 字段始终是字符串——在数值比较之前先用 int()float() 转换。

Relational Databases and Tables关系数据库与表

Four key terms for relational databases.关系数据库的四个关键术语。
  • Table — a two-dimensional grid of data: rows (records) and columns (fields/attributes). Like a CSV, but stored in the database engine.— 二维数据网格:行(记录)和列(字段/属性)。类似 CSV,但存储在数据库引擎中。
  • Primary key主键 — a column (or set of columns) whose value uniquely identifies each row. Example: student_id in a Students table. No two rows may share the same primary key.— 唯一标识每行的列(或列集合)。例如:Students 表中的 student_id。任何两行不得共享相同的主键。
  • Foreign key外键 — a column in one table that references the primary key of another table. This is the "relational" part — it links two tables together. CSTA 3A-DA-10: "Evaluate the tradeoffs in how data elements are organized."— 一个表中引用另一个表主键的列。这就是"关系"的部分——它将两个表连接在一起。CSTA 3A-DA-10:"评估数据元素组织方式的权衡。"
  • Normalisation规范化 — organising data to reduce duplication. Instead of repeating a student's name in every grade record, store the name once in the Students table and reference it by ID.— 组织数据以减少重复。与其在每条成绩记录中重复学生姓名,不如在 Students 表中存储一次姓名并通过 ID 引用。
ICS4C A2.2 (verbatim): "demonstrate the ability to read from, and write to, an external file (e.g., sequential file, database, XML file, relational database via SQL)." Note: this is the Ontario college stream (Grade 12 ICS4C), not the university stream (ICS4U).ICS4C A2.2(原文):"展示读写外部文件(如顺序文件、数据库、XML 文件、通过 SQL 的关系数据库)的能力。"注意:这是安大略学院流(12 年级 ICS4C),而非大学流(ICS4U)。
WE
Worked Example 4 · Two linked tables — Students and Grades例题 4 · 两个关联表——Students 与 Grades

Design a relational database for student grades. One table stores students; another stores assignments. Link them with a foreign key.为学生成绩设计一个关系数据库。一个表存储学生;另一个表存储作业。用外键将它们连接。

Table 1: Students (primary key = student_id).表 1:Students(主键 = student_id)。

student_idnamegrade
1Alice11
2Bob11
3Carol12

Table 2: Scores (primary key = score_id; foreign key = student_id references Students).表 2:Scores(主键 = score_id;外键 = student_id 引用 Students)。

score_idstudent_idsubjectscore
11Math92
21CS88
32Math78
43CS95

Alice's name is stored once in Students. Her two score rows in Scores reference her by student_id = 1. If her name changes, we update it in one place only — that is the benefit of normalisation. Without a relational database, every score row would repeat her full name, wasting space and risking inconsistency.Alice 的姓名在 Students 中只存储一次。她在 Scores 中的两条成绩行通过 student_id = 1 引用她。如果她的姓名变了,只需在一个地方更新——这就是规范化的好处。没有关系数据库,每条成绩行都要重复她的全名,浪费空间且容易出现不一致。

In a relational database, what is the purpose of a primary key?在关系数据库中,主键的作用是什么?
§4 · Q1
To uniquely identify each row in a table唯一标识表中的每行
To store the most important data value存储最重要的数据值
To link two tables together将两个表连接在一起
To sort the rows alphabetically按字母顺序对行排序
A primary key uniquely identifies each row — no two rows can share the same value. It is not necessarily the most important data value (it is often just an auto-incremented ID). A foreign key (not primary key) is what links two tables.主键唯一标识每行——任何两行不能共享相同的值。它不一定是最重要的数据值(通常只是一个自动递增的 ID)。外键(不是主键)才是连接两个表的东西。
Primary key = unique identifier for each row. Foreign key = a column that references the primary key of another table (linking two tables). Sorting is done by ORDER BY in SQL, not by the primary key definition.主键 = 每行的唯一标识符。外键 = 引用另一个表主键的列(连接两个表)。排序由 SQL 中的 ORDER BY 完成,不是由主键定义决定的。
A Scores table has a column student_id that references the student_id column in the Students table. What is student_id called in the Scores table?Scores 表有一列 student_id,它引用 Students 表中的 student_id 列。student_id 在 Scores 表中叫什么?
§4 · Q2
Primary key主键
Index key索引键
Foreign key外键
Composite key复合键
A column in one table that references the primary key of another table is called a foreign key. It is what makes the database "relational" — the Scores table is related to the Students table through this link.一个表中引用另一个表主键的列称为外键。这就是使数据库成为"关系型"的原因——Scores 表通过这个链接与 Students 表相关联。
Foreign key = a column that references another table's primary key. Primary key = the unique identifier of the current table's rows. An index key is a performance optimisation (not a referential constraint). A composite key is a primary key made of multiple columns.外键 = 引用另一个表主键的列。主键 = 当前表行的唯一标识符。索引键是性能优化(不是引用约束)。复合键是由多列组成的主键。

SQL Basics: SELECT and WHERESQL 基础:SELECT 与 WHERE

The four SQL keywords you need first.首先需要掌握的四个 SQL 关键字。
  • SELECT — choose which columns to return. SELECT * returns all columns; SELECT name, score returns only those two.— 选择要返回的列。SELECT * 返回所有列;SELECT name, score 只返回那两列。
  • FROM — specify the table to query. Every SELECT needs a FROM.— 指定要查询的表。每个 SELECT 都需要 FROM。
  • WHERE — filter rows. Only rows where the condition is true are returned. Operators: =, <, >, <=, >=, !=, LIKE, AND, OR.— 过滤行。只返回条件为真的行。运算符:=<><=>=!=LIKEANDOR
  • ORDER BY — sort the results. ORDER BY score DESC sorts highest-first; ASC is lowest-first (the default).— 对结果排序。ORDER BY score DESC 按从高到低排序;ASC 从低到高(默认)。
SQL is not case-sensitive for keywords, but convention capitalises them. SQL statements end with ;. ICS4C A2.2 names "relational database via SQL" explicitly. CSTA 3A-DA-10 says to "evaluate the tradeoffs in how data elements are organized and where data is stored" — SQL is the access layer on top of the organised storage.SQL 关键字不区分大小写,但约定大写。SQL 语句以 ; 结尾。ICS4C A2.2 明确点名"通过 SQL 的关系数据库"。CSTA 3A-DA-10 要求"评估数据元素组织方式和存储位置的权衡"——SQL 是有组织存储之上的访问层。
WE
Worked Example 5 · Three SQL queries on the Students/Scores tables例题 5 · 对 Students/Scores 表的三个 SQL 查询

Using the two tables from §4, write SQL queries to answer common questions.使用 §4 中的两个表,编写 SQL 查询来回答常见问题。

Query 1: Get all students.查询 1:获取所有学生。

SELECT * FROM Students;

SELECT * selects all columns; FROM Students specifies the Students table. All three rows are returned.SELECT * 选择所有列,FROM Students 从 Students 表查询。返回所有三行。

Query 2: Get names and scores where score > 85.查询 2:获取成绩 > 85 的姓名和成绩。

SELECT student_id, subject, score
FROM Scores
WHERE score > 85
ORDER BY score DESC;

WHERE score > 85 filters rows to those with a score above 85; ORDER BY score DESC sorts the results from highest to lowest (DESC = descending).WHERE score > 85 过滤条件;ORDER BY score DESC 按成绩从高到低排序(DESC = descending,降序)。

Expected result (from the §4 data):预期结果(来自 §4 数据):

student_idsubjectscore
3CS95
1Math92
1CS88

Query 3: Count how many CS scores exist.查询 3:统计 CS 成绩的条数。

SELECT COUNT(*) FROM Scores WHERE subject = 'CS';

COUNT(*) counts the number of matching rows. Result: 2 (Carol and Alice each have one CS record).COUNT(*) 计算匹配行的数量。结果:2(Carol 和 Alice 各有一条 CS 记录)。

Which SQL query returns only the name column from the Students table where the grade is 11?哪个 SQL 查询从 Students 表中只返回 grade 为 11 的 name 列?
§5 · Q1
SELECT * FROM Students;
SELECT Students WHERE grade = 11;
SELECT name WHERE grade = 11;
SELECT name FROM Students WHERE grade = 11;
A complete SELECT needs: SELECT <columns> FROM <table> WHERE <condition>. Only option D has all three parts correct: column = name, table = Students, filter = grade = 11.完整的 SELECT 需要:SELECT <列> FROM <表> WHERE <条件>。只有选项 D 三个部分都正确:列 = name,表 = Students,过滤 = grade = 11
SQL SELECT syntax: SELECT columns FROM table WHERE condition;. You must include FROM to name the table. Option A has no WHERE. Options B and C are missing FROM or SELECT columns.SQL SELECT 语法:SELECT 列 FROM 表 WHERE 条件;。必须包含 FROM 来命名表。选项 A 没有 WHERE。选项 B 和 C 缺少 FROM 或 SELECT 列。
In SQL, ORDER BY score DESC sorts the results in what order?在 SQL 中,ORDER BY score DESC 以什么顺序排序结果?
§5 · Q2
Lowest score first最低分在前
Highest score first最高分在前
Alphabetical order字母顺序
Random order随机顺序
DESC stands for descending — highest to lowest. ASC (ascending) is lowest to highest and is the default. So ORDER BY score DESC puts the highest score first in the result set.DESC 代表降序——从高到低。ASC(升序)从低到高,是默认值。所以 ORDER BY score DESC 将最高分放在结果集的第一位。
DESC = descending = highest first. ASC = ascending = lowest first (default). ORDER BY does not produce alphabetical or random ordering unless the column contains strings (for alphabetical) or you use RANDOM().DESC = 降序 = 最高在前。ASC = 升序 = 最低在前(默认)。除非列包含字符串(字母顺序)或使用 RANDOM(),否则 ORDER BY 不产生字母或随机顺序。

HTML and the Web: An IntroductionHTML 与网络:入门介绍

HTML in four facts.HTML 的四个要点。
  • HTML = HyperText Markup LanguageHTML = 超文本标记语言 — the standard language for creating web pages. A browser reads an HTML file and renders it visually. Alberta CSE1210: "Students are introduced to Internet computing through the use of one or more Web-specific markup languages."— 创建网页的标准语言。浏览器读取 HTML 文件并将其可视化渲染。阿尔伯塔 CSE1210:"学生通过使用一种或多种网络专用标记语言了解互联网计算。"
  • Tags标签 — HTML uses paired tags: <tag>content</tag>. Opening tag + content + closing tag. Self-closing tags (e.g. <br>, <img>) have no content.— HTML 使用成对标签:<标签>内容</标签>。开始标签 + 内容 + 结束标签。自闭合标签(如 <br><img>)没有内容。
  • Structure: head + body结构:head + body — every HTML page has a <head> (metadata: title, charset, links to CSS) and a <body> (visible content).— 每个 HTML 页面都有一个 <head>(元数据:标题、字符集、CSS 链接)和一个 <body>(可见内容)。
  • Key tags to know需要了解的关键标签 <h1><h6> headings, <p> paragraph, <a href="..."> link, <ul>/<li> list, <table> table, <form> form, <input> input field.<h1><h6> 标题,<p> 段落,<a href="..."> 链接,<ul>/<li> 列表,<table> 表格,<form> 表单,<input> 输入框。
WE
Worked Example 6 · A minimal HTML page displaying a data table例题 6 · 显示数据表的最小 HTML 页面

Write an HTML page that displays the Students table from §4 as a formatted web table.编写一个 HTML 页面,将 §4 的 Students 表显示为格式化的网页表格。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Student Records</title>
</head>
<body>
  <h1>Students</h1>
  <table border="1">
    <tr>
      <th>ID</th><th>Name</th><th>Grade</th>
    </tr>
    <tr><td>1</td><td>Alice</td><td>11</td></tr>
    <tr><td>2</td><td>Bob</td><td>11</td></tr>
    <tr><td>3</td><td>Carol</td><td>12</td></tr>
  </table>
</body>
</html>

<!DOCTYPE html> declares the document type as HTML5; <head> holds metadata (<meta charset="UTF-8"> sets the character encoding; <title> sets the browser-tab title); <body> contains the visible content; <table> creates a table; <tr> is a table row; <th> is a header cell; <td> is a data cell.<!DOCTYPE html> 声明文档类型为 HTML5;<head> 含元数据(<meta charset="UTF-8"> 设置字符编码,<title> 设置浏览器标签标题);<body> 含可见内容;<table> 创建表格;<tr> 是表格行(table row);<th> 是表头单元格(table header);<td> 是普通数据单元格(table data)。

In HTML, what does <a href="https://example.com">Click here</a> create?在 HTML 中,<a href="https://example.com">点击这里</a> 创建什么?
§6 · Q1
An image from the URL来自该 URL 的图片
A clickable hyperlink to example.com with text "Click here"指向 example.com 的可点击超链接,文本为"点击这里"
A form that submits to example.com提交到 example.com 的表单
A paragraph with the URL as text以 URL 为文本的段落
The <a> tag (anchor) creates a hyperlink. The href attribute specifies the destination URL. The content between the tags ("Click here") is the visible link text. Clicking it navigates to example.com.<a> 标签(锚点)创建超链接。href 属性指定目标 URL。标签之间的内容("点击这里")是可见的链接文本。点击它导航到 example.com。
The <a> tag with href creates a hyperlink, not an image (<img>), form (<form>), or paragraph (<p>).<a> 标签加 href 创建超链接,不是图片(<img>)、表单(<form>)或段落(<p>)。
Which HTML section contains the page's visible content (headings, paragraphs, tables)?哪个 HTML 部分包含页面的可见内容(标题、段落、表格)?
§6 · Q2
<body>
<head>
<title>
<meta>
The <body> element contains all visible page content. The <head> holds metadata (title, charset, CSS links — not rendered as page content). <title> sets the browser tab title (shown in the tab, not the page). <meta> provides machine-readable metadata.<body> 元素包含所有可见的页面内容。<head> 存放元数据(标题、字符集、CSS 链接——不渲染为页面内容)。<title> 设置浏览器标签标题(显示在标签中,不在页面上)。<meta> 提供机器可读的元数据。
body = visible content. head = metadata (not visible as page content). title = browser tab text. meta = machine-readable metadata.body = 可见内容。head = 元数据(不作为页面内容可见)。title = 浏览器标签文本。meta = 机器可读元数据。

Data on the Web: JSON and APIs网络上的数据:JSON 与接口

JSON and API in four facts.JSON 和接口的四个要点。
  • JSON = JavaScript Object NotationJSON = JavaScript 对象表示法 — a lightweight text format for storing and transmitting structured data. Looks like Python dictionaries and lists. Human-readable and machine-parseable. CSTA 3A-DA-12: "Create computational models that represent the relationships among different elements of data" — JSON is how those models travel over the web.— 用于存储和传输结构化数据的轻量级文本格式。看起来像 Python 字典和列表。人类可读且机器可解析。CSTA 3A-DA-12:"创建表示数据不同元素之间关系的计算模型"——JSON 就是这些模型在网络上传输的方式。
  • JSON syntaxJSON 语法 — keys must be double-quoted strings; values can be strings, numbers, booleans (true/false), null, arrays ([]), or nested objects ({}).— 键必须是双引号字符串;值可以是字符串、数字、布尔值(true/false)、null、数组([])或嵌套对象({})。
  • API = Application Programming Interface接口 = 应用程序编程接口 — a set of rules that lets one program request data or actions from another. Web APIs expose data over HTTP; the response is usually JSON. Alberta CSE2210/3210 (Client-side Scripting) and AB CSE1220 introduce this web-programming context.— 让一个程序向另一个程序请求数据或操作的一组规则。Web 接口通过 HTTP 暴露数据;响应通常是 JSON。阿尔伯塔 CSE2210/3210(客户端脚本)和 AB CSE1220 介绍这种网页编程背景。
  • Python: json modulePython:json 模块 json.loads(text) parses a JSON string into a Python dict/list; json.dumps(obj) serialises a Python object back to a JSON string.json.loads(text) 将 JSON 字符串解析为 Python 字典/列表;json.dumps(obj) 将 Python 对象序列化回 JSON 字符串。
WE
Worked Example 7 · Parsing a JSON API response in Python例题 7 · 在 Python 中解析 JSON 接口响应

A weather API returns this JSON response. Extract the city name and temperature and print them.天气接口返回以下 JSON 响应。提取城市名称和温度并打印。

Sample JSON response (the text the API sends back).示例 JSON 响应(接口返回的文本)。

{
  "city": "Toronto",
  "country": "CA",
  "temperature": 22.4,
  "humidity": 65,
  "conditions": ["cloudy", "mild"],
  "forecast": {
    "tomorrow": "rain",
    "temp_high": 18.0
  }
}

Python: parse and extract fields.Python:解析并提取字段。

import json

# Simulated API response text
response_text = '''
{
  "city": "Toronto",
  "country": "CA",
  "temperature": 22.4,
  "humidity": 65,
  "conditions": ["cloudy", "mild"],
  "forecast": {"tomorrow": "rain", "temp_high": 18.0}
}
'''

# Parse JSON string into a Python dictionary
data = json.loads(response_text)

# Access fields
city = data["city"]
temp = data["temperature"]
tomorrow = data["forecast"]["tomorrow"]

print(f"{city}: {temp}°C, tomorrow: {tomorrow}")
# Output: Toronto: 22.4°C, tomorrow: rain

import json loads the json module; json.loads(...) parses a JSON string into a Python dictionary (loads = load string); data["city"] accesses a value by key; data["forecast"]["tomorrow"] accesses a nested object by first retrieving the "forecast" dictionary, then its "tomorrow" key.import json 导入 json 模块;json.loads(...) 将 JSON 字符串(loads = load string)转为 Python 字典;data["city"] 通过键访问字典值;data["forecast"]["tomorrow"] 访问嵌套对象——先取 "forecast" 字典,再取其 "tomorrow" 键。

In JSON, which of the following is a valid key-value pair?在 JSON 中,以下哪个是有效的键值对?
§7 · Q1
name: "Alice"
'name': 'Alice'
name = "Alice"
"name": "Alice"
In JSON, keys must be double-quoted strings. Values must also use double quotes (not single quotes). So only "name": "Alice" is valid JSON. Single quotes and unquoted keys are not allowed in JSON (though they are valid in Python dicts and JavaScript objects).在 JSON 中,键必须是双引号字符串。值也必须使用双引号(不是单引号)。因此只有 "name": "Alice" 是有效的 JSON。单引号和不带引号的键在 JSON 中不被允许(尽管在 Python 字典和 JavaScript 对象中有效)。
JSON requires double-quoted keys and double-quoted string values. No single quotes, no unquoted keys, no equals signs. Only option D follows all three rules.JSON 要求双引号键和双引号字符串值。不允许单引号、不带引号的键或等号。只有选项 D 遵循所有三条规则。
Given data = {"scores": [88, 92, 75]} in Python, what does data["scores"][1] evaluate to?给定 Python 中 data = {"scores": [88, 92, 75]}data["scores"][1] 的值是什么?
§7 · Q2
92
88
75
Error — you cannot index a list inside a dict错误——不能索引字典内的列表
data["scores"] accesses the list [88, 92, 75]. Then [1] accesses index 1 of that list. Python lists are 0-indexed, so index 0 = 88, index 1 = 92, index 2 = 75. Result: 92.data["scores"] 访问列表 [88, 92, 75]。然后 [1] 访问该列表的索引 1。Python 列表从 0 开始索引,所以索引 0 = 88,索引 1 = 92,索引 2 = 75。结果:92。
Two steps: (1) data["scores"] returns the list [88, 92, 75]. (2) [1] on that list returns the item at index 1. Python is 0-indexed: index 0 = 88, index 1 = 92.两步:(1) data["scores"] 返回列表 [88, 92, 75]。(2) 对该列表 [1] 返回索引 1 处的项。Python 从 0 开始索引:索引 0 = 88,索引 1 = 92。

Exam Strategy and Common Pitfalls考试策略与常见陷阱

Data and file questions (§1–§3)数据和文件题(§1–§3)
  • Data vs information distinction.数据与信息的区别。 Examiners frequently ask: "Is this data or information? Explain." The answer always hinges on context: raw unlabelled values are data; values with meaning attached (label, unit, interpretation) are information. State the difference explicitly.考官常问:"这是数据还是信息?请解释。"答案总是取决于上下文:未标注的原始值是数据;附有含义(标签、单位、解释)的值是信息。明确说明区别。
  • CSV type-conversion pitfall.CSV 类型转换陷阱。 Every value read from a CSV is a string. Always convert with int() or float() before numeric comparison or arithmetic. Forgetting this is the single most common file-processing bug.从 CSV 读取的每个值都是字符串。在数值比较或算术之前,始终用 int()float() 转换。忘记这一点是最常见的文件处理错误。
  • File modes.文件模式。 Know "r" (read), "w" (write — overwrites), "a" (append). On an exam, if the question says "add a new record without deleting existing ones," the answer is append mode ("a").了解 "r"(读取)、"w"(写入——覆盖)、"a"(追加)。在考试中,如果题目说"添加新记录而不删除现有记录",答案是追加模式("a")。
Database and SQL questions (§4–§5)数据库和 SQL 题(§4–§5)
  • Primary vs foreign key.主键与外键。 Primary key = unique identifier for rows in its own table. Foreign key = references the primary key in another table. Mixing these up is a common error. Remember: foreign key creates the link between tables.主键 = 本表行的唯一标识符。外键 = 引用另一个表的主键。混淆这两者是常见错误。记住:外键创建表之间的链接。
  • SQL clause order.SQL 子句顺序。 Always: SELECT → FROM → WHERE → ORDER BY. You cannot write WHERE before FROM. Missing FROM is the most common SQL syntax error on exams.始终:SELECT → FROM → WHERE → ORDER BY。不能在 FROM 之前写 WHERE。缺少 FROM 是考试中最常见的 SQL 语法错误。
  • Ontario divergence.安大略分流。 If you are in ICS4U (university stream), SQL is ICS4C (college stream) content — you are not assessed on SQL in ICS4U. Your file I/O standard is A3.1. Know which course you are in.如果你在 ICS4U(大学流),SQL 是 ICS4C(学院流)内容——ICS4U 不考查 SQL。你的文件读写标准是 A3.1。了解你在哪门课程中。
HTML and JSON questions (§6–§7)HTML 和 JSON 题(§6–§7)
  • Paired tags.成对标签。 Every opening tag needs a closing tag (except self-closing ones like <br>). On a "find the error in this HTML" question, missing closing tags are the most common planted bug.每个开始标签都需要一个结束标签(除了 <br> 等自闭合标签)。在"找出 HTML 中的错误"题中,缺少结束标签是最常见的预设错误。
  • JSON double quotes only.JSON 只用双引号。 JSON keys and string values must use double quotes, not single quotes. On a "is this valid JSON?" question, single quotes or unquoted keys make it invalid.JSON 键和字符串值必须使用双引号,而非单引号。在"这是有效的 JSON 吗?"题中,单引号或不带引号的键使其无效。
  • data vs information for AP CSP.AP CSP 的数据与信息。 AP CSP Big Idea 2 (17–22% of the exam) tests whether you understand that programs can extract knowledge from raw data. When a question shows a JSON payload and asks "what knowledge can be generated from this data?" — apply the data → information transformation from §1.AP CSP 大概念 2(占考试 17–22%)测试你是否理解程序可以从原始数据中提取知识。当题目展示 JSON 载荷并问"可以从这些数据中生成什么知识?"——应用 §1 的数据 → 信息转换。
Answer hygiene作答规范
  • State the tradeoff explicitly.明确说明权衡。 CSTA 3A-DA-10 says to "evaluate tradeoffs." On a question about CSV vs database, do not just say "databases are better." State both sides: CSV is simpler and portable; a database supports complex queries and avoids duplicate data. Then state the recommendation for the given scenario.CSTA 3A-DA-10 要求"评估权衡"。在关于 CSV 与数据库的题中,不要只说"数据库更好"。说明两方面:CSV 更简单且可移植;数据库支持复杂查询并避免数据重复。然后针对给定场景说明建议。
  • Show the full SQL statement.展示完整的 SQL 语句。 On SQL questions, always write the complete statement including SELECT, FROM, and (if required) WHERE. Partial statements score partial marks at best.在 SQL 题中,始终写出完整语句,包括 SELECT、FROM 和(如需)WHERE。不完整的语句最多得部分分。

Flashcards闪卡

0 / 14 flipped0 / 14 已翻
Data vs Information数据与信息
Data = raw facts without context (e.g., 98.6). Information = data with meaning attached (e.g., "body temperature 98.6°F, normal"). CSTA 3A-DA-10/11/12.数据 = 没有上下文的原始事实(如 98.6)。信息 = 附有含义的数据(如"体温 98.6°F,正常")。CSTA 3A-DA-10/11/12。
Python file modesPython 文件模式
"r" = read only. "w" = write (overwrites). "a" = append (adds to end). Use with open(...) as f: to auto-close. AB CSE2130 outcomes 1.4.2, 1.4.5."r" = 只读。"w" = 写入(覆盖)。"a" = 追加(在末尾添加)。使用 with open(...) as f: 自动关闭。AB CSE2130 结果 1.4.2、1.4.5。
CSV header rowCSV 标题行
The first row of a CSV that names each column. Use csv.DictReader to auto-map rows to column names. All CSV values are read as strings — convert with int() or float() before math.命名每列的 CSV 第一行。使用 csv.DictReader 将行自动映射到列名。所有 CSV 值都作为字符串读取——在数学运算前用 int() 或 float() 转换。
Relational database关系数据库
A database that organises data in linked tables. Tables are joined by primary keys (unique row IDs) and foreign keys (references to another table's primary key). CSTA 3A-DA-10.将数据组织在关联表中的数据库。表通过主键(唯一行 ID)和外键(对另一个表主键的引用)连接。CSTA 3A-DA-10。
Primary key主键
A column whose value uniquely identifies each row in a table. No two rows may share the same primary key value.其值唯一标识表中每行的列。任何两行不得共享相同的主键值。
Foreign key外键
A column in one table that references the primary key of another table. Creates the relational link between tables.一个表中引用另一个表主键的列。创建表之间的关系链接。
SQL SELECT syntaxSQL SELECT 语法
SELECT columns FROM table WHERE condition ORDER BY column DESC; Always: SELECT → FROM → WHERE → ORDER BY. Missing FROM is the most common SQL error.SELECT 列 FROM 表 WHERE 条件 ORDER BY 列 DESC; 始终:SELECT → FROM → WHERE → ORDER BY。缺少 FROM 是最常见的 SQL 错误。
SQL WHERE clauseSQL WHERE 子句
Filters rows. Only rows where the condition is true are returned. Operators: =, <, >, !=, LIKE, AND, OR. E.g., WHERE score > 85 AND grade = 11.过滤行。只返回条件为真的行。运算符:=、<、>、!=、LIKE、AND、OR。例如:WHERE score > 85 AND grade = 11。
HTML structureHTML 结构
<html> contains <head> (metadata: title, charset, CSS) and <body> (visible content). Every tag has an opening and closing form except self-closing tags like <br> and <img>.<html> 包含 <head>(元数据:标题、字符集、CSS)和 <body>(可见内容)。每个标签都有开始和结束形式,除了 <br> 和 <img> 等自闭合标签。
HTML table tagsHTML 表格标签
<table> wraps the table. <tr> = table row. <th> = header cell (bold). <td> = data cell. Nest: table > tr > th/td.<table> 包裹表格。<tr> = 表格行。<th> = 表头单元格(粗体)。<td> = 数据单元格。嵌套:table > tr > th/td。
JSON format rulesJSON 格式规则
Keys must be double-quoted strings. Values can be strings, numbers, booleans (true/false), null, arrays [], or objects {}. No single quotes. No trailing commas.键必须是双引号字符串。值可以是字符串、数字、布尔值(true/false)、null、数组 [] 或对象 {}。不允许单引号。不允许尾随逗号。
json.loads() vs json.dumps()json.loads() 与 json.dumps()
json.loads(text) = parse JSON string → Python dict/list. json.dumps(obj) = serialise Python dict/list → JSON string. "loads" = load string; "dumps" = dump string.json.loads(text) = 解析 JSON 字符串 → Python 字典/列表。json.dumps(obj) = 序列化 Python 字典/列表 → JSON 字符串。"loads" = 加载字符串;"dumps" = 转储字符串。
API (web context)接口(网络背景)
Application Programming Interface. A set of rules that lets one program request data from another over HTTP. Response is usually JSON. AB CSE1210/1220/2210/3210 web scripting pathway.应用程序编程接口。让一个程序通过 HTTP 向另一个程序请求数据的一组规则。响应通常是 JSON。AB CSE1210/1220/2210/3210 网页脚本路径。
AP CSP Big Idea 2 (DAT)AP CSP 大概念 2(DAT)
Data is central to computing — it communicates initial conditions and represents new knowledge. Topics 2.3 (extracting information from data) and 2.4 (using programs with data). Weighted 17–22% of the exam.数据是计算的核心——它传递初始条件并代表新知识。主题 2.3(从数据中提取信息)和 2.4(将程序与数据结合使用)。占考试 17–22%。

Practice Quiz综合测验

A program reads the number 37 from a CSV file. What Python type does the variable hold immediately after reading?程序从 CSV 文件中读取数字 37。读取后变量立即持有什么 Python 类型?
Q1
int整数 int
float浮点数 float
str字符串 str
bool布尔值 bool
CSV files are plain text. Every value read from a CSV — including numbers — is a string (str) until you convert it. Use int(row["score"]) or float(row["score"]) before doing math.CSV 文件是纯文本。从 CSV 读取的每个值——包括数字——都是字符串(str),直到你转换它。在进行数学运算之前使用 int(row["score"])float(row["score"])
CSV values are always strings. Python does not auto-convert CSV text to int or float. You must call int() or float() explicitly.CSV 值始终是字符串。Python 不会自动将 CSV 文本转换为 int 或 float。必须显式调用 int() 或 float()。
A Students table has columns student_id, name, grade. A Scores table has columns score_id, student_id, subject, score. What is student_id called in the Scores table?Students 表有列 student_idnamegrade。Scores 表有列 score_idstudent_idsubjectscorestudent_id 在 Scores 表中叫什么?
Q2
Primary key主键
Foreign key外键
Index索引
Header标题
In the Scores table, student_id references the primary key of the Students table. A column that references another table's primary key is a foreign key. It creates the relational link between the two tables.在 Scores 表中,student_id 引用 Students 表的主键。引用另一个表主键的列是外键。它创建两个表之间的关系链接。
In the Scores table, student_id is a foreign key (it references Students.student_id). The primary key of Scores is score_id (the unique identifier for each row in Scores).在 Scores 表中,student_id 是外键(它引用 Students.student_id)。Scores 的主键是 score_id(Scores 中每行的唯一标识符)。
Which SQL query returns the names of all students in grade 12, sorted alphabetically?哪个 SQL 查询返回所有 12 年级学生的姓名,按字母顺序排列?
Q3
SELECT * WHERE grade = 12 ORDER BY name;
SELECT name FROM Students grade = 12;
SELECT name FROM Students ORDER BY name WHERE grade = 12;
SELECT name FROM Students WHERE grade = 12 ORDER BY name;
Correct SQL clause order: SELECT → FROM → WHERE → ORDER BY. Option D has all four in the right order: SELECT name (column), FROM Students (table), WHERE grade = 12 (filter), ORDER BY name (sort). ASC is the default (alphabetical = ascending).正确的 SQL 子句顺序:SELECT → FROM → WHERE → ORDER BY。选项 D 四个都按正确顺序:SELECT name(列),FROM Students(表),WHERE grade = 12(过滤),ORDER BY name(排序)。ASC 是默认值(字母顺序 = 升序)。
SQL clause order is fixed: SELECT → FROM → WHERE → ORDER BY. Missing FROM (option A), missing WHERE keyword (option B), and wrong ORDER BY position (option C) all make those queries invalid.SQL 子句顺序是固定的:SELECT → FROM → WHERE → ORDER BY。缺少 FROM(选项 A)、缺少 WHERE 关键字(选项 B)和 ORDER BY 位置错误(选项 C)都使这些查询无效。
In HTML, which tag creates a hyperlink to another page?在 HTML 中,哪个标签创建指向另一页面的超链接?
Q4
<a href="url">
<link href="url">
<src="url">
<p href="url">
The <a> (anchor) tag with the href attribute creates a hyperlink. <link> is used in the <head> to link external CSS stylesheets. <p> is a paragraph. There is no <src> tag.<a>(锚点)标签加 href 属性创建超链接。<link> 在 <head> 中用于链接外部 CSS 样式表。<p> 是段落。没有 <src> 标签。
Hyperlinks use the anchor tag: <a href="url">text</a>. The <link> tag in the head links CSS files, not navigational hyperlinks.超链接使用锚点标签:<a href="url">文本</a>。head 中的 <link> 标签链接 CSS 文件,不是导航超链接。
A JSON object is {"name": "Bob", "scores": [78, 85, 91]}. What does data["scores"][2] evaluate to in Python?JSON 对象为 {"name": "Bob", "scores": [78, 85, 91]}。在 Python 中 data["scores"][2] 的值是什么?
Q5
78
85
91
Error错误
data["scores"] returns the list [78, 85, 91]. Python lists are 0-indexed: index 0 = 78, index 1 = 85, index 2 = 91. So data["scores"][2] = 91.data["scores"] 返回列表 [78, 85, 91]。Python 列表从 0 开始索引:索引 0 = 78,索引 1 = 85,索引 2 = 91。所以 data["scores"][2] = 91。
Python is 0-indexed. data["scores"] = [78, 85, 91]. Index 0 = 78, index 1 = 85, index 2 = 91.Python 从 0 开始索引。data["scores"] = [78, 85, 91]。索引 0 = 78,索引 1 = 85,索引 2 = 91。
Which CSTA standard says "Create interactive data visualizations using software tools to help others better understand real-world phenomena"? 🇺🇸 CSTA哪个 CSTA 标准说"使用软件工具创建互动数据可视化,以帮助他人更好地理解现实世界现象"?🇺🇸 CSTA
Q6
3A-DA-10
3A-DA-11
3A-DA-12
3B-DA-05
CSTA 3A-DA-11 (verbatim): "Create interactive data visualizations using software tools to help others better understand real-world phenomena." 3A-DA-10 is about data storage tradeoffs. 3A-DA-12 is about computational models of relationships.CSTA 3A-DA-11(原文):"使用软件工具创建互动数据可视化,以帮助他人更好地理解现实世界现象。"3A-DA-10 关于数据存储权衡。3A-DA-12 关于关系的计算模型。
3A-DA-10 = data storage/organisation tradeoffs. 3A-DA-11 = interactive data visualisation. 3A-DA-12 = computational models of data relationships. 3B-DA-05 = data analysis tools for complex systems.3A-DA-10 = 数据存储/组织权衡。3A-DA-11 = 互动数据可视化。3A-DA-12 = 数据关系的计算模型。3B-DA-05 = 复杂系统的数据分析工具。

Readiness Checklist准备就绪清单

Tick each item when you can do it cold, without notes, on a first attempt.能在无笔记、首次尝试下完成,再勾选每一项。

0 / 11 mastered已掌握 0 / 11

What This Feeds Into本单元的去向

Data, databases and the web are the infrastructure that every modern program rests on. The skills here — reading files, parsing CSV and JSON, querying a database, building a web page — underpin the AP CSP Create Performance Task (your program must handle real data), the CSTA 3A-DA standards, and the data-handling sections of Ontario's Grade 12 Computer Science courses. No AP CSA database or web guide exists in this repo yet; the section below focuses on within-series and AP CSP connections.数据、数据库和网络是每个现代程序所依赖的基础设施。这里的技能——读取文件、解析 CSV 和 JSON、查询数据库、构建网页——支撑 AP CSP 创作绩效任务(程序必须处理真实数据)、CSTA 3A-DA 标准和安大略 12 年级计算机科学课程的数据处理部分。本仓库中目前没有 AP CSA 数据库或网页指南;以下部分重点介绍系列内和 AP CSP 的连接。

Within High School Computer Science.在 HS Computer Science 内部。

Unit 2 (Programming Fundamentals) gave you variables, data types, and I/O — this unit shows where that data lives on disk and in databases. Unit 5 (Data Structures) shows how to organise data in memory (lists, dictionaries); this unit shows how to persist it on disk or transmit it over the web. Unit 9 (Boolean Logic) underpins the WHERE clause logic you used in §5. The data skills here synthesise material from across the series into a complete pipeline: file → parse → filter → display.第 2 单元(编程基础)给了你变量、数据类型和 I/O——本单元展示这些数据在磁盘和数据库中的存储位置。第 5 单元(数据结构)展示如何在内存中组织数据(列表、字典);本单元展示如何将其持久化到磁盘或通过网络传输。第 9 单元(布尔逻辑)支撑你在 §5 中使用的 WHERE 子句逻辑。这里的数据技能将整个系列的材料综合成一个完整的管线:文件 → 解析 → 过滤 → 显示。

AP CSP feeder (no link — no AP database guide in this repo).AP CSP 衔接(无链接——本仓库中没有 AP 数据库指南)。

AP CSP Big Idea 2 (Data — DAT) is weighted at 17–22% of the exam and directly tests the skills in this guide: extracting information from data (topics 2.3, 2.4), understanding how programs generate knowledge from raw inputs, and evaluating tradeoffs in data storage and representation (CSTA 3A-DA-10). The Create Performance Task requires you to write a program that processes data — the CSV-reading and JSON-parsing patterns in §2, §3, and §7 are the practical skills that task demands. There is no AP CSA database or web guide in this repo; students moving to AP CSA should treat this unit as enrichment background for data persistence concepts that AP CSA covers through file I/O and 2D arrays.AP CSP 大概念 2(数据——DAT)占考试 17–22%,直接考查本指南中的技能:从数据中提取信息(主题 2.3、2.4)、理解程序如何从原始输入生成知识,以及评估数据存储和表示的权衡(CSTA 3A-DA-10)。创作绩效任务要求编写处理数据的程序——§2、§3 和 §7 中的 CSV 读取和 JSON 解析模式是该任务要求的实践技能。本仓库中没有 AP CSA 数据库或网页指南;转向 AP CSA 的学生应将本单元视为 AP CSA 通过文件 I/O 和二维数组涵盖的数据持久化概念的拓展背景。