There are a lot of developers who manipulate databases using an ORM and don’t know more SQL than the “classic” SELECT … FROM … WHERE … queries. But databases have various unknown features that can avoid programing data processing. One of them is CTE (for Common Table Expressions).
This article describes how to use this feature with PHP Doctrine ORM.