In this chapter, we learned about some advanced SQL concepts and features, such as CTEs and window functions. These features, for example, allow us to implement a logic that wouldn't be possible otherwise, that is, recursive queries.
The other techniques explained here, such as the DISTINCT ON clause, grouping sets, the FILTER clause, and lateral subqueries, could be replaced by simple structures. However, that would require a lot of coding, and the result would be more complex and would work more slowly.
SQL can be used to implement very complicated logic. However, in difficult cases, queries can become overcomplicated and hard to maintain. Moreover, sometimes, it isn't possible to do certain things in pure SQL. In these cases, you need a procedural language to implement an algorithm. The next chapter will introduce one of them: PL/pgSQL.