<?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: Aarooshi Tyagi</title>
    <description>The latest articles on DEV Community by Aarooshi Tyagi (@aarooshi_tyagi_482c07709d).</description>
    <link>https://dev.to/aarooshi_tyagi_482c07709d</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%2F4271717%2F23236aa9-705e-4540-b2fb-86a7fe72a017.png</url>
      <title>DEV Community: Aarooshi Tyagi</title>
      <link>https://dev.to/aarooshi_tyagi_482c07709d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aarooshi_tyagi_482c07709d"/>
    <language>en</language>
    <item>
      <title>What SQL Can Tell Us About Banking Fraud: 5 Practical Examples</title>
      <dc:creator>Aarooshi Tyagi</dc:creator>
      <pubDate>Sun, 29 Nov 2026 05:07:55 +0000</pubDate>
      <link>https://dev.to/aarooshi_tyagi_482c07709d/what-sql-can-tell-us-about-banking-fraud-5-practical-examples-313j</link>
      <guid>https://dev.to/aarooshi_tyagi_482c07709d/what-sql-can-tell-us-about-banking-fraud-5-practical-examples-313j</guid>
      <description>&lt;p&gt;A suspicious transaction doesn't necessarily mean someone has committed fraud. This is something that becomes increasingly clear when you start working with banking data.&lt;/p&gt;

&lt;p&gt;Imagine a customer making several high-value transactions within an hour. It could be someone shopping for a wedding, a business owner paying suppliers, or someone using a compromised account.&lt;/p&gt;

&lt;p&gt;The data might look similar in all three cases.&lt;/p&gt;

&lt;p&gt;That's what makes fraud analytics interesting. Finding unusual activity is relatively straightforward. Understanding what that activity actually means is the difficult part.&lt;/p&gt;

&lt;p&gt;While there is a lot of discussion around AI and machine learning in fraud detection, SQL remains an incredibly useful tool for investigating suspicious behaviour.&lt;/p&gt;

&lt;p&gt;Here are five examples worth exploring if you're interested in banking, data analytics or financial crime investigation.&lt;/p&gt;

&lt;p&gt;The examples use fictional banking data and PostgreSQL syntax.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. When transaction frequency suddenly increases
&lt;/h2&gt;

&lt;p&gt;Banks process millions of transactions, and customers have different spending habits. Rather than looking at transaction amounts alone, analysts can also examine how frequently transactions occur.&lt;/p&gt;

&lt;p&gt;A simple exploratory query might look like this:&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;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS transaction_count,
    SUM(amount) AS total_amount
FROM transactions
WHERE transaction_time &amp;gt;=
      CURRENT_TIMESTAMP - INTERVAL '1 hour'
GROUP BY customer_id
ORDER BY transaction_count DESC;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting part is what happens after running the query.&lt;/p&gt;

&lt;p&gt;A customer appearing at the top of the results isn't necessarily suspicious. Someone who regularly makes business payments may have a perfectly reasonable explanation for their activity.&lt;/p&gt;

&lt;p&gt;Comparing recent activity with historical behaviour gives the analyst more context than transaction frequency alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Finding duplicate transactions
&lt;/h2&gt;

&lt;p&gt;Duplicate transactions are something analysts frequently encounter while working with financial data.&lt;/p&gt;

&lt;p&gt;Sometimes they're caused by processing errors. In other cases, they may be associated with suspicious activity or problems in the payment system.&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;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;merchant_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;transaction_time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS occurrence_count
FROM transactions
GROUP BY
    customer_id,
    merchant_id,
    amount,
    transaction_time
HAVING COUNT(*)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This identifies records sharing the same customer, merchant, amount and timestamp.&lt;/p&gt;

&lt;p&gt;One thing to be careful about here is data quality. If an upstream process has loaded the same records twice, the query could produce misleading results.&lt;/p&gt;

&lt;p&gt;Before investigating a customer, it makes sense to investigate the data itself.&lt;/p&gt;

&lt;p&gt;Not every problem appearing on a fraud dashboard is actually a fraud problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Understanding changes in customer spending
&lt;/h2&gt;

&lt;p&gt;Suppose a customer generally makes small purchases, but their recent spending looks considerably different.&lt;/p&gt;

&lt;p&gt;Instead of applying the same assumptions to every customer, we can calculate an individual historical spending baseline.&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;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;average_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;MIN&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;minimum_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;maximum_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS transaction_count
FROM transactions
WHERE transaction_time &amp;gt;=
      CURRENT_TIMESTAMP - INTERVAL '90 days'
  AND transaction_time &amp;lt;
      CURRENT_TIMESTAMP - INTERVAL '1 day'
GROUP BY customer_id;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives us a basic picture of historical spending behaviour.&lt;/p&gt;

&lt;p&gt;Of course, averages have limitations. A few exceptionally large transactions can distort the results. Customers with limited transaction history present another challenge.&lt;/p&gt;

&lt;p&gt;Depending on the available data, median spending, transaction categories and longer-term behavioural patterns may provide a more useful comparison.&lt;/p&gt;

&lt;p&gt;The SQL isn't particularly complicated. Deciding which comparison makes business sense requires more thought.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Looking beyond financial transactions
&lt;/h2&gt;

&lt;p&gt;One of the more interesting aspects of banking fraud is that relevant information doesn't always originate from the transaction itself.&lt;/p&gt;

&lt;p&gt;Customer service interactions, authentication events and account maintenance activities can provide additional context during an investigation.&lt;/p&gt;

&lt;p&gt;For example, an analyst might want to understand the different account maintenance activities recorded across the customer population.&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;SELECT&lt;/span&gt;
    &lt;span class="n"&gt;event_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS total_events,
    COUNT(DISTINCT customer_id) AS customers
FROM account_events
GROUP BY event_type
ORDER BY total_events DESC;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This could include activities such as contact information updates, password changes or other account maintenance events.&lt;/p&gt;

&lt;p&gt;These events are normal parts of banking operations. Their presence alone should never be treated as proof of fraud.&lt;/p&gt;

&lt;p&gt;What matters is understanding the broader circumstances and evaluating the available evidence together.&lt;/p&gt;

&lt;p&gt;This is also where fraud analytics starts moving closer to fraud investigation.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Checking whether your fraud data is reliable
&lt;/h2&gt;

&lt;p&gt;This might not sound as exciting as building a machine learning model, but data quality deserves considerably more attention than it usually receives.&lt;/p&gt;

&lt;p&gt;Imagine building a fraud dashboard where transaction IDs are duplicated or customer identifiers are missing.&lt;/p&gt;

&lt;p&gt;Even a technically correct SQL query could produce an incorrect business conclusion.&lt;/p&gt;

&lt;p&gt;Here's a basic validation query:&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;SELECT&lt;/span&gt;
    &lt;span class="nb"&gt;COUNT&lt;/span&gt;&lt;span class="cm"&gt;(*) AS total_records,
    COUNT(DISTINCT transaction_id) AS unique_transactions,
    SUM(
        CASE
            WHEN customer_id IS NULL THEN 1
            ELSE 0
        END
    ) AS missing_customer_ids,
    SUM(
        CASE
            WHEN amount IS NULL THEN 1
            ELSE 0
        END
    ) AS missing_amounts
FROM transactions;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I would encourage anyone learning fraud analytics to spend some time understanding data validation, reconciliation and completeness checks.&lt;/p&gt;

&lt;p&gt;These skills are just as valuable as knowing window functions, joins or advanced SQL techniques.&lt;/p&gt;

&lt;p&gt;A beautiful dashboard built on unreliable data isn't particularly useful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where fraud examination fits into all of this
&lt;/h2&gt;

&lt;p&gt;SQL can help answer questions about what happened, how frequently something occurred and whether certain patterns exist.&lt;/p&gt;

&lt;p&gt;It cannot independently determine whether someone intended to commit fraud.&lt;/p&gt;

&lt;p&gt;That requires an understanding of evidence, internal controls, investigative procedures and the circumstances surrounding an event.&lt;/p&gt;

&lt;p&gt;This is one reason why the Certified Fraud Examiner (CFE) credential is relevant to professionals working in fraud analytics, banking, risk management and financial crime.&lt;/p&gt;

&lt;p&gt;The technical side helps you find unusual patterns. Fraud examination helps you understand how to evaluate them.&lt;/p&gt;

&lt;p&gt;For anyone interested in developing that knowledge alongside their technical skills, &lt;a href="https://fincertprep.com/" rel="noopener noreferrer"&gt;FinCertPrep&lt;/a&gt; is an independent CFE preparation and fraud education platform.&lt;/p&gt;

&lt;p&gt;Official certification requirements and examination information are available directly from the &lt;a href="https://www.acfe.com/" rel="noopener noreferrer"&gt;Association of Certified Fraud Examiners&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Something worth thinking about
&lt;/h2&gt;

&lt;p&gt;If your SQL query identifies 500 suspicious transactions, but only five eventually turn out to be confirmed fraud, was your analysis successful?&lt;/p&gt;

&lt;p&gt;There isn't a universal answer.&lt;/p&gt;

&lt;p&gt;You would need to understand the financial losses prevented, the investigation workload, the impact on genuine customers and the purpose of the original detection rule.&lt;/p&gt;

&lt;p&gt;These are the kinds of questions that make fraud analytics more than just a technical discipline.&lt;/p&gt;

&lt;p&gt;Learning SQL is a great starting point. Learning how to ask the right business questions is what makes the technical knowledge valuable.&lt;/p&gt;

&lt;p&gt;I'd be interested to hear how others working in banking, financial crime or data analytics approach this problem. Do you prefer starting with SQL-based analysis or moving directly towards statistical and machine learning models?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: This article introduces FinCertPrep, an independent educational platform that is not affiliated with the ACFE.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>datascience</category>
      <category>fintech</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
