title: Get all data in specified time and list all this transaction too in T-SQL
body: <p>I have this demo database </p>
  
  <pre><code>create database testGroupfirst22;
  go
  
  use testGroupfirst22;
  go
  
  create table testTbl 
  (
      id int primary key identity,
      custnum nvarchar(50),
      transDate datetime,
      degree int 
  )
  
  insert into testTbl 
  values ('ahmed', '1-1-2000', 50), ('ahmed', '1-1-2000', 500),
         ('ahmed', '2-1-2000', 660), ('ahmed', '2-1-2000', 666),
         ('ahmed', '3-1-2000', 50),
         ('ali', '1-1-2000', 5054), ('ali', '1-1-2000', 1500),
         ('ali', '1-1-2000', 66220), ('ali', '1-1-2000', 6656),
         ('ali', '1-1-2000', 540),
         ('hasan', '1-1-2000', 50), ('hasan', '1-1-2000', 50),
         ('hasan', '1-1-2000', 500), ('hasan', '1-1-2000', 660),
         ('hasan', '1-1-2000', 666), ('hasan', '1-1-2000', 50)
  </code></pre>
  
  <p>This is the output </p>
  
  <p><a href="https://i.stack.imgur.com/HaoRY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HaoRY.png" alt="enter image description here"></a></p>
  
  <p>I wrote this code to get all transaction in specified time that more than 1950
  and it worked like this </p>
  
  <pre><code>select 
      custnum, sum(degree) as [all transaction] 
  from 
      testTbl
  where 
      transdate between '1-1-2000' and '3-1-2000' 
  group by 
      custnum
  having 
      sum(degree) &gt; 2000
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/aWgzm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aWgzm.png" alt="enter image description here"></a></p>
  
  <p>But I need to list all this transaction and history of it with the same code 
  like this </p>
  
  <p><a href="https://i.stack.imgur.com/KRYyF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KRYyF.png" alt="enter image description here"></a></p>
  
  <p>I believe that this could be happen using subquery but I think that there are  a performance issues using this and I found many questions that recommend using cross apply and other window - ranking but I'm not familiar with these ways and I got stuck with this query and I couldn't reach to the wright solution yet .</p>