I've been asked for a school exercise to write the following query:
SELECT ACCOUNT_ID, AVG(AMOUNT)
FROM ACCOUNTS A
INNER JOIN TRANSACTIONS T ON A.ACCOUNT_ID = T.ACCOUNT_ID
GROUP BY ACCOUNT_ID
The focus of the exercise is to perform the whole statement without including new transactions registered while it is in progress. My first thought was to use the highest isolation level Serializable or set the transaction Readonly. But I'm wondering however if it's really necessary.
Can be a single statement like this considered atomic? If it's the case, does it mean that the engine works on the datas as they are when the query starts?
If it's not the case, what is the correct way to do that?