It's hard to imagine doing this with a ton of duplication. I have written SQL by hand and there are probably more confusing corners than in shell, which is saying a lot!
Depending on what database server you are on you might not he constrained to just SQL.
Now, PSQL isn't exactly all that friendly of a language either, but it does you to somewhat break stuff up into functions and reuse code across different SQL statements.
Now, PSQL isn't exactly all that friendly of a language either, but it does you to somewhat break stuff up into functions and reuse code across different SQL statements.