summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-04-30 14:35:04 -0600
committermo khan <mo.khan@gmail.com>2020-04-30 14:35:04 -0600
commit4be3f841402da6b7666481da6ed499415058a21d (patch)
tree71b33129ea54d42218f05c3f7f3204adcf4221a3
parent84840049606d9ca363f4db384d3865754b67b012 (diff)
create index
-rw-r--r--assignments/exam/README.md29
1 files changed, 29 insertions, 0 deletions
diff --git a/assignments/exam/README.md b/assignments/exam/README.md
index 1f23031..fdda0dc 100644
--- a/assignments/exam/README.md
+++ b/assignments/exam/README.md
@@ -248,3 +248,32 @@ WHERE m.name IN (
HAVING COUNT(p.manager_name) > 20
):
```
+
+## 4
+
+Consider the following database.
+
+```text
+TRAVEL-AGENT (name, age, salary)
+CUSTOMER (name, departure_city, destination, journey_class)
+TRANSACTION (number, cust_name, travel_agent_name, amount_paid)
+```
+
+a. Write a SQL query to display the names of all travel agents who arranged trips for customer "John Smith".
+
+```sql
+SELECT ta.name
+FROM "Travel-Agent" ta
+WHERE ta.name IN (
+ SELECT DISTINCT(travel_agent_name)
+ FROM TRANSACTION t
+ WHERE t.cust_name = 'John Smith'
+);
+```
+
+b. Define indexes on selected attributes to speed up your query. Justify your selections.
+
+```sql
+CREATE INDEX ON "Travel-Agent" (name); -- Joining on travel_agent.name
+CREATE INDEX ON Transaction (cust_name); -- filtering by cust_name
+```