Orders

Example 1

Calculate the total revenues from Orders, and the min, max and average Order amount:

SELECT 
  count(*) as OrdersNumber, 
  sum(Amount) AS TotalRevenuesFromOrders, 
  min(Amount) as MinAmount,
  (sum(Amount)/count(*)) as AverageAmount,
  max(Amount) as MaxAmount
FROM Orders

In the Browse Tab of Studio, using the query above, this is the visualized result:

Example 2

Find the year of the Orders, and how many Orders have been placed in the same year:

SELECT 
  count(*) as OrdersCount, 
  OrderDate.format('yyyy') AS OrderYear 
FROM Orders 
GROUP BY OrderYear 
ORDER BY OrdersCount DESC

In the Browse Tab of Studio, using the query above, this is the visualized result:

Example 3

Find the 3 Customers who placed most Orders:

SELECT 
  OrderedId as CustomerId,
  in("HasCustomer").size() AS NumberOfOrders 
FROM Customers 
ORDER BY NumberOfOrders 
DESC LIMIT 3

In the Browse Tab of Studio, using the query above, this is the visualized result:

Example 4

Find the top 3 Customers in terms of spending:

SELECT 
  customer.OrderedId as customerOrderedId, 
  SUM(order.Amount) as totalAmount 
FROM (
  MATCH {Class: Customers, as: customer}<-HasCustomer-{class: Orders, as: order} 
  RETURN customer, order
) 
GROUP BY customerOrderedId 
ORDER BY totalAmount DESC 
LIMIT 3

In the Browse Tab of Studio, using the query above, this is the visualized result:

Example 5

Find all Orders placed by Customer with Id 2:

MATCH {class: Customers, as: c, where: (OrderedId=1)}<-HasCustomer-{class: Orders, as: o} 
RETURN $pathelements

In the Graph Editor included in Studio, using 'RETURN $pathelements' as RETURN clause, this is the obtained graph:

Example 6

Calculate the total revenues from Orders associated with Customer with Id 2:

SELECT sum(Amount) as TotalAmount 
FROM (
  SELECT expand(in('HasCustomer'))
  FROM Customers
  WHERE OrderedId=2
)

In the Browse Tab of Studio, using the query above, this is the obtained list of records:

results matching ""

    No results matching ""