I have a table like this:
I need to write a query that returns the accounts that have more than one transaction per day and the number of days on which the threshold is passed.
So in the above case I would get:
Any ideas?
Code:
Declare @transactions Table(tran_id Integer, account_id Integer, tran_date datetime)
Insert Into @transactions Values(1, 1, '2006-06-08 08:00:00')
Insert Into @transactions Values(2, 1, '2006-06-08 14:00:00')
Insert Into @transactions Values(3, 2, '2006-06-09 08:00:00')
Insert Into @transactions Values(4, 1, '2006-06-09 08:00:00')
Insert Into @transactions Values(5, 1, '2006-06-10 08:00:00')
Insert Into @transactions Values(6, 1, '2006-06-10 15:00:00')
Insert Into @transactions Values(7, 3, '2006-06-10 09:00:00')
Insert Into @transactions Values(8, 3, '2006-06-10 12:00:00')
I need to write a query that returns the accounts that have more than one transaction per day and the number of days on which the threshold is passed.
So in the above case I would get:
Code:
account_id num_days
1 2
3 1
Any ideas?