What is the purpose of common table expressions in SQL and when should you use them?