Upload
neo4j-the-fastest-and-most-scalable-native-graph-database
View
244
Download
1
Embed Size (px)
Citation preview
Categories
CategoryID
CategoryName
Suppliers
SupplierID
CompanyName
Products
ProductID
ProductName
CategoryID
SupplierID
Customers
CustomerID
CompanyName
Order Details
OrderID
ProductID
Orders
OrderID
CustomerID
ShipVia
EmployeeID
Employees
EmployeeID
FirstName
LastName
ReportsTo
Shippers
ShipperID
CompanyName
EmployeeTerritories
EmployeeID
TerritoryID
Territories
TerritoryID
TerritoryDescription
RegionID
Regions
RegionID
RegionDescription
Order
Product
Employee
Category
Supplier
Customer
Shipper
Territory
Region
Employee
REPORTS TO
Product
Employee
REPORTS TO
Export from SQL
SELECT * FROM Orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ',' ESCAPED BY ''
LINES TERMINATED BY '\r\n';
...
SELECT * FROM Products
INTO OUTFILE '/tmp/products.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ',' ESCAPED BY ''
LINES TERMINATED BY '\r\n';
SQL
SELECT Products.ProductName AS Product,ROUND(SUM((`Order Details`.UnitPrice*Quantity*(1-Discount)/100)*100)) AS SalesFROM Employees
JOIN Orders ON Employees.EmployeeID = Orders.EmployeeIDJOIN `Order Details` ON Orders.OrderID = `Order Details`.OrderIDJOIN Products ON `Order Details`.ProductID = Products.ProductID
WHERE Employees.FirstName = "Steven" AND Employees.LastName = "Buchanan"GROUP BY Products.ProductNameORDER BY Sales DESC LIMIT 5;
Output
+------------------------+-------+
° Product ° Sales °
+------------------------+-------+
° Cte de Blaye ° 8432 °
° Raclette Courdavault ° 7920 °
° Mozzarella di Giovanni ° 5829 °
° Alice Mutton ° 5538 °
° Perth Pasties ° 5084 °
+------------------------+-------+
Cypher
MATCH (e:Employee)-[:SOLD]->(:Order)-[r:INCLUDED]->(p:Product)
WHERE e.first_name = 'Steven' AND e.last_name = 'Buchanan'
RETURN p.name AS Product,
ROUND(SUM(r.unit_price*r.quantity*(1-r.discount)/100)*100) AS Sales
ORDER BY Sales DESC LIMIT 5;
Output
+-----------------------------------+
| Product | Sales |
+-----------------------------------+
| "Cte de Blaye" | 8432 |
| "Raclette Courdavault" | 7920 |
| "Mozzarella di Giovanni" | 5829 |
| "Alice Mutton" | 5538 |
| "Perth Pasties" | 5084 |
+-----------------------------------+
SQL
SELECT CONCAT(Employees.FirstName, ' ', Employees.LastName) AS Name,CONCAT(e2.FirstName, ' ', e2.LastName) AS Manager,CONCAT(e3.FirstName, ' ', e3.LastName) AS `Manager's Manager`
FROM EmployeesJOIN Employees AS e2 ON Employees.ReportsTo = e2.EmployeeIDJOIN Employees AS e3 ON e2.ReportsTo = e3.EmployeeID;
Output
+----------------+-----------------+-------------------+
° Name ° Manager ° Manager's Manager °
+----------------+-----------------+-------------------+
° Michael Suyama ° Steven Buchanan ° Andrew Fuller °
° Robert King ° Steven Buchanan ° Andrew Fuller °
° Anne Dodsworth ° Steven Buchanan ° Andrew Fuller °
+----------------+-----------------+-------------------+
Cypher
MATCH p = (:Employee)-[:REPORTS_TO*2]->(:Employee)RETURN EXTRACT(n IN NODES(p) |
n.first_name + ' ' + n.last_name) AS reporting;
Output
+------------------------------------------------------+
| reporting |
+------------------------------------------------------+
| ["Michael Suyama","Steven Buchanan","Andrew Fuller"] |
| ["Robert King","Steven Buchanan","Andrew Fuller"] |
| ["Anne Dodsworth","Steven Buchanan","Andrew Fuller"] |
+------------------------------------------------------+