title: SQL - Select record count from column value in separate table
body: <p>I'm totally stumped here, I hope I haven't overlooked an answer elsewhere.</p>
  
  <p>I have two tables, <code>asset</code> and <code>purchase_order</code>.</p>
  
  <p><strong>asset</strong></p>
  
  <pre><code>asset_key | description | purchase_order_key
  </code></pre>
  
  <p><strong>purchase_order</strong></p>
  
  <pre><code>purchase_order_key | order_number | number_of_assets
  </code></pre>
  
  <p>I'm trying to get a list of purchase orders, each meeting the following criteria: </p>
  
  <ul>
  <li>The total number of rows in the asset table with the given purchase_order_key is less than the number_of_assets value in the purchase_order row with that purchase_order_key.</li>
  </ul>
  
  <p>For example, say the <code>asset</code> table has 4 rows with the same <code>purchase_order_key</code> (24), and 17 items with a different <code>purchase_order_key</code> (66). If <code>purchase_order</code> 24 lists 4 <code>number_of_assets</code>, and <code>purchase_order</code> 66 lists 19 <code>number_of_assets</code>, then the query should return <code>purchase_order</code> 66, but not <code>purchase_order</code> 24.</p>