MATCH (e:Employee) RETURN count(e) AS `Number of employees`;
MATCH (e:Employee)
RETURN e.lastName AS Last, e.firstName AS First, e.title AS Title
ORDER BY Last;
MATCH (p:Product) WHERE p.productName CONTAINS 'Sauce' OR p.productName CONTAINS 'sauce' RETURN p.productName AS Product;
MATCH (p:Product) WHERE p.productName =~ '.*[S|s]auce.*' RETURN p.productName AS Product;
MATCH (p:Product) WHERE toLower(p.productName) CONTAINS 'sauce' RETURN p.productName AS Product;
MATCH (c:Category)
WHERE toLower(c.description) CONTAINS 'sauce'
RETURN c.categoryName AS Category;
MATCH (c:Customer)-[r:PURCHASED]->(o:Order) RETURN DISTINCT c.companyName AS Customer ORDER BY Customer;
MATCH (c:Customer)-[r:PURCHASED]->(o:Order) WITH COLLECT (DISTINCT c.customerID) AS Ordered MATCH (c:Customer) WHERE NOT (c.customerID IN Ordered) RETURN DISTINCT c.companyName AS Customer ORDER BY Customer;
MATCH (c:Customer)-[r1:PURCHASED]->(o:Order)-[r2:CONTAINS]->(p:Product) WHERE toLower(p.productName) CONTAINS 'chai' RETURN DISTINCT c.companyName AS Customer;
MATCH (c)-[r1:PURCHASED]->(o)-[r2:CONTAINS]->(p)
RETURN c.companyName AS Customer, round(sum(r2.unitPrice*r2.quantity)) AS Value
ORDER BY Value DESC;
MATCH (p)-[:PART_OF]->(c)
RETURN c.categoryName AS Category, p.productName AS Product
ORDER BY Category, Product;
MATCH (p)-[:PART_OF]->(c)
WITH c.categoryName AS Category, count(p.productName) as Count
RETURN Category, Count
ORDER BY Category;
MATCH (o)-[r:CONTAINS]->(p)
WITH o.orderID AS Order, sum(r.unitPrice*r.quantity) AS Value
RETURN min(Value);
MATCH (c)-[r1:PURCHASED]->(o)-[r2:CONTAINS]->(p)
WITH c.companyName AS Customer, o.orderID AS Order, sum(r2.unitPrice*r2.quantity) AS Value
RETURN Customer, Value
ORDER BY Value
LIMIT 1;
MATCH (c)-[r1:PURCHASED]->(o)-[r2:CONTAINS]->(p) WHERE c.companyName = 'Blauer See Delikatessen' RETURN sum(r2.unitPrice*r2.quantity) AS Value;
MATCH(e)-[:REPORTS_TO]->(m) WHERE m.firstName = 'Andrew' AND m.lastName = 'Fuller' RETURN (e.firstName + ' ' + e.lastName) AS Employee ORDER BY e.lastName;
MATCH (e)-[r1:SOLD]->(o)<-[r2:PURCHASED]-(c)
WHERE c.companyName = 'Blauer See Delikatessen'
RETURN (e.firstName + ' ' + e.lastName) AS Employee
ORDER BY e.lastName;
MATCH (o)-[r:CONTAINS]->(p)
RETURN o.orderDate.year as Year, round(sum(r.unitPrice*r.quantity)) AS Value
ORDER BY Year
Basket of goods analysis: A common retail analytics task is to analyze each basket or order to learn what products are often purchased together. Report the names of products that appear in the same order three or more times.
MATCH (o1:Order)-[r1:CONTAINS]->(p1:Product), (o2:Order)-[r2:CONTAINS]->(p2:Product) WHERE o1.orderID = o2.orderID AND p1.productName <> p2.productName AND p1.productID > p2.productID RETURN (p1.productName + ' and ' + p2.productName), COUNT (p1.productName + ' ' + p2.productName) AS Frequency ORDER BY Frequency DESC;
ABC reporting: Compute the revenue generated by each customer based on their orders. Also, show each customer's revenue as a percentage of total revenue. Sort by customer name.
MATCH (o:Order)-[r:CONTAINS]->(p:Product) WITH round(sum(r.unitPrice*r.quantity)) as Total MATCH (c:Customer)-[r1:PURCHASED]->(o:Order)-[r2:CONTAINS]->(p:Product) RETURN c.companyName AS Customer, round(sum(r2.unitPrice*r2.quantity)) AS Value, round(sum(r2.unitPrice*r2.quantity)/Total*100) AS Percent ORDER BY Value DESC;
Same as Last Year (SALY) analysis: Compute the ratio for each product of sales for 1997 versus 1996.
MATCH (o1:Order)-[r1:CONTAINS]->(p:Product)<-[r2:CONTAINS]-(o2:Order) WHERE o1.orderDate.year = 1996 AND o2.orderDate.year = 1997 RETURN p.productName AS Product, apoc.math.round(((sum(r1.unitPrice*r1.quantity)/sum(r2.unitPrice*r2.quantity))*100),2) AS `SALY 96/97 as %` ORDER BY `SALY 96/97 as %` DESC;
This page is part of the promotional and support
material for Data Management (open edition) by Richard T. Watson For questions and comments please contact the author |