title: Progress query to remove duplicates based on number of duplicates
body: <p>Our accounting department needs pull tax data from our MIS every month and submit it online to the Dept. of Revenue.  Unfortunately, when pulling the data, it is duplicated a varying number of times depending on which jurisdictions we have to pay taxes to.  All she needs is the dollar amount for one jurisdiction, for one line, because she enters that on the website.</p>
  
  <p>I've tried using DISTINCT to pull only one record of the type, in conjunction with LEFT() to pull just the first 7 characters of the jurisdiction but it ended up excluding certain results that should have been included.  I believe it was because the posting date and the amount on a couple transactions was identical.  They were separate transactions but the query took them as duplicates and ignored them.</p>
  
  <p>Here is a couple of examples of queries I've run that have been successful in pulling most of the data, but most times either too much or not enough:</p>
  
  <pre><code>    SELECT DISTINCT LEFT("Sales-Tax-Jurisdiction-Code", 7), "Taxable-Base", "Posting-Date"
      FROM ARInvoiceTax
      WHERE ("Posting-Date" &gt;= '2019-09-01' AND "Posting-Date" &lt;= '2019-09-30') 
      AND (("Sales-Tax-Jurisdiction-Code" BETWEEN '55001' AND '56763') 
      OR "Sales-Tax-Jurisdiction-Code" = 'Dakota Cty TT')
      ORDER BY "Sales-Tax-Jurisdiction-Code"
  </code></pre>
  
  <p>Here is a query that I can to pull all of the data and the subsequent result is below that:</p>
  
  <pre><code>    SELECT "Sales-Tax-Jurisdiction-Code", "Taxable-Base", "Posting-Date"
      FROM ARInvoiceTax
      WHERE ("Posting-Date" &gt;= '2019-09-01' AND "Posting-Date" &lt;= '2019-09-30') 
      AND (("Sales-Tax-Jurisdiction-Code" BETWEEN '55001' AND '56763') 
      OR "Sales-Tax-Jurisdiction-Code" = 'Dakota Cty TT')
      ORDER BY "Sales-Tax-Jurisdiction-Code"
  </code></pre>
  
  <p>Below is a sample of the output:</p>
  
  <pre><code>Jurisdiction | Tax Amount | Posting Date
  -------------|------------|-------------
  5512100City  |  $50.00    | 2019-09-02
  5512100City  |  $50.00    | 2019-09-03
  5512100City  |  $70.00    | 2019-09-02
  5512100Cnty  |  $50.00    | 2019-09-02
  5512100Cnty  |  $50.00    | 2019-09-03
  5512100Cnty  |  $70.00    | 2019-09-02
  5512100State |  $70.00    | 2019-09-02
  5512100State |  $50.00    | 2019-09-02
  5512100State |  $50.00    | 2019-09-03
  5513100Cnty  |  $25.00    | 2019-09-12
  5513100State |  $25.00    | 2019-09-12
  5514100City  |  $9.00     | 2019-09-06
  5514100City  |  $9.00     | 2019-09-06
  5514100Cnty  |  $9.00     | 2019-09-06
  5514100Cnty  |  $9.00     | 2019-09-06
  5515100State |  $12.00    | 2019-09-11
  5516100City  |  $6.00     | 2019-09-13
  5516100City  |  $7.00     | 2019-09-13
  5516100State |  $6.00     | 2019-09-13
  5516100State |  $7.00     | 2019-09-13
  </code></pre>
  
  <p>As you can see, the data can be all over the place.  One zip code could have multiple different lines.  What the accounting department does now is prints a report with this information and, in a spreadsheet, only records (1) dollar amount per transaction.  For example, for 55121, she would need to record $50.00, $50.00 and $70.00 (she tallies them and adds the total amount on the website) however the SQL query gives me those (3) numbers, (3) times.</p>
  
  <p>I can't seem to figure out a query that will pull only one set of the data.  Unfortunately, I can't do it based on the words/letters after the 00 because not all jurisdictions have all 3 (city, cnty, state) and thus trying to remove lines based on that removes valid lines as well.</p>