In this activity, we will practice translating our human questions into queries our robot counterparts can understand. As usual, you will not be required to turn in anything. For your convenience, we have included a short example of how to typeset relational algebra notation in a Jupyter notebook.
You can use TeX-style commands to include mathematical expressions in Jupyter notebook. In a markdown cell, just include the commands you want wrapped in $ to have an inline expression and $$ if you want centered equation typesetting.
$$basic-cust-accts \leftarrow \Pi_{(name, customer.sin, account-number)}
(\sigma_{customer.sin = account.sin}(customer \times account))$$
| Operation | Symbol | LaTeX Name |
|---|---|---|
| Assign | $\rightarrow$ | rightarrow |
| Select | $\sigma$ | sigma |
| Project | $\Pi$ | Pi |
| Inner product | $\bowtie$ | bowtie |
| Cross product | $\times$ | times |
| Rename | $\rho$ | rho |
| Groupby | $\gamma$ | gamma |
| And | $\wedge$ | wedge |
| Or | $\vee$ | vee |
| Negation | $\neg$ | neg |
Consider the following schema below. The key fields are underlined, and the domain is listed after the field names. The Catalog table contains prices for Balloons sold by different Clowns standing at certain booths in a fair.
Clowns(cid integer, cname text, booth text)
Balloons(bid integer, bshape text, bcolor text)
Catalog(cid integer, bid integer, cost float)
Write your answer here, replacing this text.
Write your answer here, replacing this text.
Write your answer here, replacing this text.
SQL query goes here...
SQL query goes here...
SQL query goes here...
Recall the schema for the representation of a matrix in SQL: matrix(x, y, value). In lecture, someone asked how the matrix transpose would be defined in SQL. Let's think about the implementation. First, we should think about the definition. Let $M$ denote a matrix and $[M]_{ij}$ be the element in the $i^{th}$ row and $j^{th}$ column. The matrix transpose is defined as
$$[M^T]_{ij}=[M]_{ji}$$
This suggests that all we naively have to do is make a SELECT statement that swaps x and y. Hint: $\rho(Mt, (1\rightarrow y, 2 \rightarrow x), M)$
SQL query goes here...