I have the following query in MSSQL:
select
TRANSACTION_TYPE_ID
,COUNT(TRANSACTION_TYPE_ID)AS NUMBER_OF_TRANSACTIONS
,CAST(SUM(AMOUNT)AS DECIMAL (30,2)) AS TOTAL
FROM
[ONLINE_TRANSACTION]
WHERE CONVERT(CHAR(8), CREATED_ON, 114) >='17:30' AND AMOUNT IS NOT NULL AND
TRANSACTION_TYPE_ID !='CHEQUE-STOP-TRANS-TYPE'
GROUP BY TRANSACTION_TYPE_ID
ORDER BY TRANSACTION_TYPE_ID
I want to show the type of transactions TRANSATION_TYPE_ID
as above the total amount of each type of transaction as above BUT also the average time these transactions occurred CREATED_ON
which is datetime
I still have not find a good way of doing this?
If your talking about the time of day and not looking to get a specific date, ie. 5:32 instead of Jan 4, 2012 5:32, the below could help. Sorry about the caps, it's the way I'm used to writing SQL.
One way would be to convert the time to seconds, calculate the average, and then convert it back to hours, minutes and seconds for the result.
Based on Randolph Potter's answer, you can find the average time like: