Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello,I am interested in executing a T-SQL query that allows me to retrieve those accconts who have 3 OR MORE sale transactions back to back, within 60-minutes of one another (time interval). Example: An account can have 4 sale transactions for the same day (2010-08-02), but not necessarly meet the 60-minute time interval criteria, so they should be exclucde. I need to only query those transactions that meet a 3 or more transaction count, all within 60-minutes of one another. Any suggestions? Example:ACCOUNT DATE00001 2010-08-02 22:27:22.96700001 2010-08-02 22:27:44.89700001 2010-08-02 22:28:15.47700001 2010-08-10 11:34:57.02000002 2010-08-31 14:58:33.27700002 2010-08-31 20:11:25.633
russell
Pyro-ma-ni-yak
5072 Posts
Posted - 2010-09-15 : 14:39:18
here is one way. someone else may have something better.
Thanks Russell, Looks like this approach may work. Any thoughts on how I can further add an aggregate to this query? Example, 3 sale transactions or greater, within 60-minutes of each other, and the sum of the sales >= $300.Table: MyTableACCOUNT-------------DATE-----------------------------TranAmt00001---------------2010-08-02 22:27:22.967----------$100.0000001---------------2010-08-02 22:37:44.897----------$100.0000001---------------2010-08-02 22:58:15.477----------$100.0000001---------------2010-08-10 11:34:57.020-----------$14.9900002---------------2010-08-31 14:58:33.277-----------$50.0000002---------------2010-08-31 20:11:25.633-----------$40.00expected results:ACCOUNT-------------DATE-----------------------------TranAmt00001---------------2010-08-02 22:27:22.967----------$100.0000001---------------2010-08-02 22:37:44.897----------$100.0000001---------------2010-08-02 22:58:15.477----------$100.00Thanks!