Skip to content

1 or 2 credits, some free · 1 credit is about $1

pocketshelf

Payments Ledger SQL: Data Cleanup Queries

A 2-page snippet pack for data cleanup and maintenance queries for a payments ledger database (wallets and transactions): 12 short entries with copy-ready code.

ForDevelopers

sql-cleanup-queries-for-payments-ledger.pdfShowing 18 of 72 lines
// Find duplicate account_number
SELECT account_number, count(*)
FROM wallets
GROUP BY account_number
HAVING count(*) > 1;

// Delete duplicates, keep the newest
DELETE FROM wallets
WHERE id IN (
  SELECT id FROM (
    SELECT id, row_number() OVER (PARTITION BY lower(account_number) ORDER BY id DESC) AS rn
    FROM wallets
  ) t
  WHERE rn > 1
);

// Trim stray whitespace
UPDATE wallets

What's inside

Format
PDF, Markdown, SQL
Contents
12 queries
Version
1.0 · Updated 3 Oct 2026
Licence
Commercial What this means
Checked
Checked before it ships
  • sql-cleanup-queries-for-payments-ledger.pdfPDF · 21 KB
  • sql-cleanup-queries-for-payments-ledger.mdMarkdown · 2 KB
  • sql-cleanup-queries-for-payments-ledger.sqlSQL · 2 KB
  • LICENSE.txtadded to every download

About this item

A compact, printable snippet pack for data cleanup and maintenance queries for a payments ledger database (wallets and transactions). Each of the 12 entries has a one-line explanation and a small example you can paste into your editor. The PDF uses a two-column A4 layout designed to sit next to your keyboard, and the same content ships as Markdown so you can search it or drop it into your notes, plus a .sql file with every query. Every SQL example targets PostgreSQL 16.

Reviews

No reviews yet.

You might also grab