Data Warehousing Lab sheets
  • CITS3401/5504 Lab Sheets
  • Week 1 - Introduction (Self-Reading)
  • Week 2 - Software Setup
  • Week 3 - Extract, transform, and load (ETL)
    • Task Demonstration Video
  • Week 4 - Designing a New Data Warehouse
  • Week 5 - Mini End-to-End Data Warehouse Project
  • Week 6 - Association Rules Mining
  • Week 8 - Neo4j
  • Week 9 - Import data from a relational database into Neo4j
  • Week 10 - Cypher Queries
    • Week 10 Sample Solution
  • Week 11 - Advanced Cypher and APOC
    • Week 11 Sample Solution
  • Week 12 - Graph Data Science
    • Week 12 Sample Solution
Powered by GitBook
On this page
  • 1. READ
  • 2. UPDATE
  • 3. DELETE
  1. Week 10 - Cypher Queries

Week 10 Sample Solution

1. READ

  1. What does the following query mean?

MATCH (p:Product {brand: "Mega"})-[:CONTAINS]->(s:Sale)-[r:SOLD_IN {year: 2021}]->(sh:Shop)
RETURN DISTINCT sh

Sample Answer: This query is used to find shops that sold products of the brand "Mega" in the year 2021 without duplicated values.

2. UPDATE

  1. Compare Figure 1 with Figure 3. What's the difference between their results?

Sample Answer: In Figure 1, the data type of "127.0" is a string. In Figure 3, the data type of 127.0 is float.

  1. Verify whether the price of product "BED_3" has been correctly updated to 125.0.

Sample Answer:

MATCH (p:Product {productID: "BED_3"})
RETURN p.productID, p.purchasePrice
  1. Choose a shop and update its size to a different value.

Sample Answer: Assume the select shop's id is shop_15, and the size will be updated to big.

MATCH (s:Shop {shopID: "shop_15"})
SET s.shopSize = 'big'
RETURN s.shopID, s.shopSize
  1. Update the "unitPrice" property of all Sale nodes to float.

Sample Answer:

MATCH (s:Sale)
SET s.unitPrice = toFloat(s.unitPrice)
RETURN s.unitPrice
  1. Without changing the type of "quantity" for sale nodes, update the sale whose "SaleID" is "S000004969" to have a quantity of "5.0".

Sample Answer:

MATCH (s:Sale {saleID: "S000004969"})
SET s.quantity = 5.0
RETURN s.saleID, s.quantity

3. DELETE

  1. What is the difference between "DELETE" and "DETACH DELETE"?

Sample Answer:

  • DELETE: The DELETE clause is used to delete nodes, relationships or paths. But it is not possible to delete nodes with relationships connected to them without also deleting the relationships.

  • DETACH DELETE: This command extends the functionality of DELETE by automatically removing any relationships that the node is involved in before deleting the node itself.

  1. Delete all nodes and relationships in the database.

Sample Answer:

MATCH (n)
DETACH DELETE n
PreviousWeek 10 - Cypher QueriesNextWeek 11 - Advanced Cypher and APOC

Last updated 1 year ago