It wouldn't be a SQL statement, but rather PHP code you would need to write.

Same, I think, for your second question - custom code.