Yes, SQL Challenges should be considered on topic because...
they provide the community with new approaches to existing problems.
they show the more exotic forms of SQL, and are an invaluable way to hone your craft.
they are popular and may attract new expert users to the site
We love fun
SQL Challanges (as described in the question) are neither automatically on-topic, nor off-topic.
Each question should be evaluated on its merits by the community.
I would expect questions of this type to be well-received, if they:
Fit in Q & A format
Are clearly presented and explained
Contain sufficient information to identify correct answers
Is it SPAM?
No. Not by the network's standards. See the FAQ What are the “spam” and “rude or abusive” (offensive) flags, and how do they work? which says in part:
A post should be marked as spam only if it advertises a product, service, or similar and is unsolicited or lacks disclosure.
If the question had been barely more than a link to that ...
No, SQL Challenges should be considered off topic because...
they belong on Programming Puzzles & Code Golf (PPCG) (but please read their help center before posting there)
our Q & A is not set up to handle this type of activity well
PPCG has code snippets (to generate a leaderboard) and a sandbox etc.
they're not practical, answerable questions ...
As it is, the post basically redirects you to an external site where one could earn real or imaginary brownie points for answering it. It essentially encourages you to post the answer on that external site, which obviously doesn't benefit Stack Exchange at all. No additional information can be found at the external site to help answer the question.
No, but continue to allow moderator/community discretion for questions that don't quite fit, but produce sufficiently interesting answers.
Worth noting is that neither question you have linked is closed. A question that starts "What are different ways to…" is a red flag for other reasons, whether it is on-topic or not, which just goes to show that the ...
Not all closures will fall precisely into the exact interpretation of the wording jammed into generic close reason text. No matter how much we fiddle with that text, someone is not going to be happy that it didn't 100% accurately reflect the closure reason behind their question.
In this case, I'm not sure there's a more accurate close reason for "give me ...
Assuming the 'too trivial' premise is correct (if it is not, please disconsider), perhaps we could improve the close reason to:
"Too localized - this could be because your code has a typo, basic error, or it is not relevant to most of our audience, or is too trivial. Consider revising your question so that it appeals to a broader audience. As it stands,...
We don't need a new close reason for this.
The volume of licensing questions doesn't justify it
Existing close reasons can be used (e.g. too localized/too broad/opinion-based)
A link to the relevant meta discussion is sufficient to provide context:
Are licensing questions within our scope?
I just don't feel it is worth cluttering up the vote to close page ...