I find at my job I often have to join the same table on itself, partly because I have no control of the DB design, and partly because things are wanted pretty custom most of the time.
Select distinct t.label, z.dupCount
From optevents t
Join
(select label, Count(*) dupCount
from optevents
group By label
Having Count(*) > 1) z
On z.label = t.label
where t.campaignId = 100
order By dupCount Desc
I'm curious how I can convert this to a Django ORM lookup?
The Model definition is pretty simple, no foreign keys at all.