<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Incode Labs Global</title>
    <description>The latest articles on DEV Community by Incode Labs Global (@incodelabs_global).</description>
    <link>https://dev.to/incodelabs_global</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4236124%2Fb5c0f11e-3ea0-4684-aca0-2788b11a6a5c.png</url>
      <title>DEV Community: Incode Labs Global</title>
      <link>https://dev.to/incodelabs_global</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/incodelabs_global"/>
    <language>en</language>
    <item>
      <title>Catch an order-total mismatch with one SQL query</title>
      <dc:creator>Incode Labs Global</dc:creator>
      <pubDate>Tue, 10 Nov 2026 02:13:07 +0000</pubDate>
      <link>https://dev.to/incodelabs_global/catch-an-order-total-mismatch-with-one-sql-query-1e90</link>
      <guid>https://dev.to/incodelabs_global/catch-an-order-total-mismatch-with-one-sql-query-1e90</guid>
      <description>&lt;p&gt;Order #1044 shows a recorded total of $620. The receipt shows two items at $60 each. Before correcting a report, calculate the expected total and isolate the row that needs a closer look.&lt;/p&gt;

&lt;p&gt;Disclosure: Incode Labs builds CareerTree. This post was drafted with AI assistance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run the check
&lt;/h2&gt;

&lt;p&gt;This example uses synthetic data. Each row represents one order line, and prices are stored as integer cents. Paste it into SQLite.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="nf"&gt;order_lines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;unit_price_cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;recorded_total_cents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1044&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;62000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1045&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;unit_price_cents&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;expected_cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;recorded_total_cents&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="n"&gt;recorded_total_cents&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;unit_price_cents&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;difference_cents&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;order_lines&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;recorded_total_cents&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;unit_price_cents&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only order #1044 appears. The expected line total is $120 and the recorded total is $620, a $500 difference. In real data, confirm that the fields are both line totals on the same tax, discount, and currency basis before treating the difference as an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write the finding
&lt;/h2&gt;

&lt;p&gt;“Order #1044 is $500 above the amount on the receipt. I’d check the source transaction before updating the report.” That gives a teammate the row, the evidence, and a next step.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/S5HgfGCaTcs" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The clip shows this practice task in CareerTree. If you want to try it on your phone, the app is available on &lt;a href="https://apps.apple.com/app/id6816567098?pt=129382340&amp;amp;ct=ct-dv-01&amp;amp;mt=8" rel="noopener noreferrer"&gt;iPhone&lt;/a&gt; and &lt;a href="https://play.google.com/store/apps/details?id=com.incodelabs.careertree&amp;amp;referrer=utm_source%3Ddevto%26utm_medium%3Dorganic%26utm_campaign%3Dct-dv-01" rel="noopener noreferrer"&gt;Android&lt;/a&gt; in supported countries. It contains ads and optional purchases.&lt;/p&gt;

</description>
      <category>sql</category>
    </item>
  </channel>
</rss>
