title: SQL Query to filter record for particular record count
body: <p>I have a table which have Identity, RecordId, Type, Reading And IsDeleted columns. Identity is primary key that is auto increment, RecordId is integer that can have duplicate values, Type is a type of reading that can be either 'one' or 'average', Reading is integer that contains any integer value, and IsDeleted is bit that can be 0 or 1 i.e. false or true. 
  Now, I want the query that contains all the records of table in such a manner that if COUNT(Id) for each RecordId is greater than 2 then display all the records of that RecordId.  </p>
  
  <p>If COUNT(Id) == 2 for that specific RecordId and Reading value of both i.e. 'one' or 'average' type of the records are same then display only average record. </p>
  
  <p>If COUNT(Id) ==1 then display only that record.</p>
  
  <p>For example : </p>
  
  <pre><code>Id          RecordId          Type          Reading       IsDeleted 
  1           1                 one             4              0
  2           1                 one             5              0
  3           1                 one             6              0
  4           1                 average         5              0
  5           2                 one             1              0
  6           2                 one             3              0
  7           2                 average         2              0
  8           3                 one             2              0
  9           3                 average         2              0
  10          4                 one             5              0
  11          4                 average         6              0
  12          5                 one             7              0
  </code></pre>
  
  <p>Ans result can be </p>
  
  <pre><code>Id          RecordId          Type          Reading       IsDeleted 
  1           1                 one             4              0
  2           1                 one             5              0
  3           1                 one             6              0
  4           1                 average         5              0
  5           2                 one             1              0
  6           2                 one             3              0
  7           2                 average         2              0
  9           3                 average         2              0
  10          4                 one             5              0
  11          4                 average         6              0
  12          5                 one             7              0
  </code></pre>
  
  <p>In short I want to skip the 'one' type reading which have an average reading with same value and its count for 'one' type reading not more than one.</p>