OrientDB aggregation query
OrientDB is an open source Multi-model database that supports graphic database, document database and key value database. It provides various aggregation query functions, including SUM, COUNT, AVG, MIN, MAX, and so on. Here are some common examples of aggregation queries:
Table structure and sample data:
Suppose we have a table called 'orders' that contains the following fields:
-ID (integer, primary key)
-Customer_ ID (integer, foreign key)
-Order_ Date
-Price (Floating-point arithmetic number)
1. COUNT Aggregation Query: Counting Order Quantity
SELECT COUNT(*) FROM orders
2. SUM aggregation query: calculating total sales revenue
SELECT SUM(price) FROM orders
3. AVG aggregation query: calculating average sales revenue
SELECT AVG(price) FROM orders
4. MIN aggregation query: Find the lowest sales amount
SELECT MIN(price) FROM orders
5. MAX aggregation query: Find the highest sales revenue
SELECT MAX(price) FROM orders
6. GROUP BY Aggregate Query: Calculate Total Sales by Customer Group
SELECT customer_id, SUM(price) FROM orders GROUP BY customer_id
7. HAVING aggregation query: Find customers with total sales revenue greater than 1000
SELECT customer_id, SUM(price)
FROM orders
GROUP BY customer_id
HAVING SUM(price) > 1000
These examples demonstrate some of the aggregation query functions of OrientDB. In practical applications, you can use these aggregated queries to analyze and statistically analyze data based on specific business needs.