If you want to reuse a piece of SQL code fragments multiple times, use macros. Macros in dbt are like functions in Python.
My full article about dbt.