How to do this in SQL?

Original text of this message