SQL Query for Average Transaction Value by Day

This problem asks for a SQL query that returns the average transaction value for each day. The example input table has three days, with transaction values of 10, 20, and 30 respectively. The expected output table would have the same three days, with average values of 10, 15, and 20.

Problem

Write a SQL query that returns the average transaction value for each day.
Example input:
| day | transaction_value |
| --- | ----------------- |
| 1   | 10                |
| 2   | 20                |
| 3   | 30                |
Example output:
| day | average_value |
| --- | ------------- |
| 1   | 10            |
| 2   | 15            |
| 3   | 20            |

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT day, AVG(transaction_value) AS average_value
FROM table
GROUP BY day;

/*

The solution above is optimal because it uses the AVG function to calculate the average value for each day.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the AVG function to calculate the average value for each day.

Evaluated at: 2022-11-10 02:15:56