If the number of transactions is small enough to query quickly, a simple SQL query will give you that. If the number of transactions is very large, querying a random sample of perhaps 1 in 1000 will give you reasonably accurate results. You can calculate the probable error from the sample size.
There are questions which require examining all the data, but often you don't really need to.
There are questions which require examining all the data, but often you don't really need to.