SQL Server - Orders By Client with 1 minute difference -
i have table 3 columns
clientid | orderid | createddate 1 | 1 | 2015-10-27 10:00:00 1 | 2 | 2015-10-27 10:00:30 2 | 3 | 2015-10-27 10:30:30 3 | 4 | 2015-10-27 10:35:00 3 | 5 | 2015-10-27 10:35:45 3 | 6 | 2015-10-27 12:30:00
i want count number of orders same client inserted (more or less) in same minute.
this way expected result be
clientid | count(orderid) 1 | 2 2 | 1 3 | 2 3 | 1
i've tried using inner join wasn't able it. suggestions?
try this:
create table #myorders ( clientid int, orderid int, createddate datetime ) insert #myorders values (1,1,'2015-10-27 10:00:00'), (1,2,'2015-10-27 10:00:30'), (2,3,'2015-10-27 10:30:30'), (3,4,'2015-10-27 10:35:00'), (3,5,'2015-10-27 10:35:45'), (3,6,'2015-10-27 12:30:00') select clientid, count(*) [count(orderid)] #myorders group clientid, dateadd(minute, datediff(minute, 0, createddate), 0)
this gives
clientid count(orderid) -------- -------------- 1 2 2 1 3 2 3 1
Comments
Post a Comment