← SQL workplace practice

Sets multiplicity and evidence · Original fictional data · Free files and full answers

Compare feed pairs for exact multiset equality

For every feed pair a<b return feed_a,feed_b,difference_copies as the sum of absolute per-key count differences across their key union. Include zero for exact multiset matches. Sort pair.

Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.

Your output contract

  1. For every feed pair a<b return feed_a,feed_b,difference_copies as the sum of absolute per-key count differences across their key union. Include zero for exact multiset matches. Sort pair.
  2. Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
  3. These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.

Return columns exactly as feed_a, feed_b, difference_copies. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.

Source data

features

10 source rows · Download features CSV

entity TEXTfeature TEXT
Ax
Ay
Ay
Bx
By
Cx
Dz
Ex
Ey
Ez

feeds

10 source rows · Download feeds CSV

feed TEXTkey TEXT
onea
onea
oneb
oned
twoa
twoc
twod
threea
threed
threee

evidence

5 source rows · Download evidence CSV

claim TEXTsource TEXTowner TEXT
C1s1O1
C1s2O1
C2s3O1
C2s4O2
C3s5O3
Field dictionary and schema
features:
  entity TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  feature TEXT — Literal business key or category label. Match exactly and retain NULL where present.

feeds:
  feed TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  key TEXT — Literal business key or category label. Match exactly and retain NULL where present.

evidence:
  claim TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  source TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  owner TEXT — Literal business key or category label. Match exactly and retain NULL where present.

Download complete SQLite setup

A method you can reuse

  1. For every feed pair a<b return feed_a,feed_b,difference_copies as the sum of absolute per-key count differences across their key union. Include zero for exact multiset matches. Sort pair.
  2. For the first output record, feed_a = one; feed_b = three; difference_copies = 3.
  3. Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

Watch for this wrong turn

Equal total row counts or equal distinct keys do not establish equality of duplicate multiplicities.

Run and check in SQLite

Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.

Complete worked SQL and expected output
WITH f AS (SELECT DISTINCT feed FROM feeds), k AS (SELECT DISTINCT key FROM feeds), c AS (SELECT feed,key,COUNT(*) n FROM feeds GROUP BY feed,key) SELECT a.feed feed_a,b.feed feed_b,SUM(ABS(COALESCE(x.n,0)-COALESCE(y.n,0))) difference_copies FROM f a JOIN f b ON a.feed<b.feed CROSS JOIN k LEFT JOIN c x ON x.feed=a.feed AND x.key=k.key LEFT JOIN c y ON y.feed=b.feed AND y.key=k.key GROUP BY a.feed,b.feed ORDER BY a.feed,b.feed;
"feed_a","feed_b","difference_copies"
"one","three","3"
"one","two","3"
"three","two","2"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects