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

Last updated