Replies: 1 comment 1 reply
-
You can try smth like this for example: exists_case =
DB.from(Sequel[:direct_debits].as(:d2))
.where(Sequel[:d2][:loan_id] =~ Sequel[:d1][:loan_id])
# more conditions here
.exists
DB.from(Sequel[:direct_debits].as(:d1)).where(status: "rejected").exclude(exists_case) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I've been poking at this for over a day now and have only really served to illuminate just how little I understand the Sequel toolkit.
I'm trying to code up something pretty simple in SQL. I've got a table called
direct_debits
that has some obvious fields:loan_id
,status
,amount
,due_date
andprocessed_date
(there are others, but trying to simplify here). I'm attempting to display rejected debits unless there has been a subsequent resubmission of the amount.My current query shows all the rejected debits except for any that have the same due debit in a different state with a later processed date:
Am I right in thinking this is just not possible in Sequel? I've tried so many things my head just hurts. I get that I can do a better job of tracking that the resubmitted debit is actually this debit, but that's totally not my problem here. I'm just finding the toolkit pretty much impenetrable.
The best I've got so far is something like this (but I know it's wrong and every little variation of it just explodes, probably including this one):
I've tried recasting it as a cte expression, but that ended up just returning every row no matter what I varied. I've even asked ChatGPT but it hallucinated something mental.
Help!
Beta Was this translation helpful? Give feedback.
All reactions