title: How to count the number of entries in a subquery
body: <p>I want to count the number of times the account number occurs per each loan ID, instead of per each lt.type.</p>
  
  <pre><code>SELECT *
  FROM
  (
  SELECT DISTINCT a.ACCOUNTNUMBER AS [Account Number]
      , CONCAT(n.FIRST, ' ', n.MIDDLE, ' ', n.LAST) AS [Member Name]
      , l.id AS [Loan ID]
      , COUNT(a.ACCOUNTNUMBER)
          OVER(partition by a.ACCOUNTNUMBER) as [Number of Tracking Record] 
      , n.EMAIL AS [Email]
      , n.HOMEPHONE AS [Phone Number]
  FROM dbo.account a
  INNER JOIN dbo.LOAN l
      ON a.ACCOUNTNUMBER = l.PARENTACCOUNT
  INNER JOIN dbo.LOANTRACKING lt
      ON l.PARENTACCOUNT = lt.PARENTACCOUNT
      AND l.ID = lt.ID
  INNER JOIN dbo.NAME n 
      ON a.ACCOUNTNUMBER = n.PARENTACCOUNT
  WHERE lt.type = 46
      AND l.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 112)
      AND lt.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 
  112)
      AND n.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 112)
      AND a.ProcessDate = CONVERT(VARCHAR(8), dateadd(day,-1, getdate()), 112)
      AND l.CLOSEDATE IS NULL
      AND lt.EXPIREDATE IS NULL
      AND n.type = 0
  GROUP BY a.ACCOUNTNUMBER, n.FIRST, n.MIDDLE, n.LAST, l.id, n.email, 
  n.HOMEPHONE, lt.type
  ) MyQuery
  WHERE MyQuery.[Number of Tracking Record] &gt;= 2
  GROUP BY [Account Number], [Member Name], [Loan ID], [Number of Tracking 
  Record], [Email], [Phone Number]
  ORDER BY [Account Number]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pUpKN.png" rel="nofollow noreferrer">Here's what my query is giving me now</a></p>
  
  <p><a href="https://i.stack.imgur.com/QUced.png" rel="nofollow noreferrer">Here's what the result should be</a></p>