How to select average from row result on oracle?

by cali_green , in category: Third Party Scripts , a month ago

How to select average from row result on oracle?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , a month ago

@cali_green 

To select the average from a row result on Oracle, you can use the AVG() function along with the query to calculate the average of the values in the row. Here's an example:


Let's say you have a table named "sales" with columns "product_id", "category", "sales_2021", and "sales_2020". To calculate the average of the sales for each product in 2021 and 2020, you can use the following query:

1
2
3
SELECT product_id, AVG(sales_2021 + sales_2020) AS average_sales
FROM sales
GROUP BY product_id;


This query will calculate the average of the sum of sales in 2021 and 2020 for each product and display the result in the "average_sales" column.