In postgreSQL, we can use filter such as-
SELECT column_name,
SUM(sales) FILTER (WHERE year = 2022) AS total_sales_2022,
SUM(sales) FILTER (WHERE year = 2023) AS total_sales_2023
FROM sales_table
GROUP BY column_name;
How can we implement this in Apache age? Anyone help me plz.
2
Answers
In apacheAGE we are not dealing with tables, but with nodes and edges.
Those nodes/edges hold information though their labels and/or properties. For example :
Here we create 4 different nodes with
Person
as the label, and their respectivename
as property. If we want to find a node through its label we can do:This will return all the nodes in our graph that belong to the
Person
label. Similarly we can filter through a property of a node for example:Here this will return only the nodes that have the property
name
and it equals'John'
.As per the Doc,
An equivalent cypher query would be:
This query will match for the products, filter on the year and apply aggregation using
COUNT
(analogous toGROUP BY
). Then you can applySUM
aggregation function to calculate the total sales for each product.