Common Table Expression (CTE) aka WITH clause

Code
-- Common feature in RDBMS, but new in MySQL 8.0, MariaDB 10.2.1

WITH low_price_history (cost, label, status) AS (
  SELECT 
    price,
    name,
    status
  FROM history
  WHERE price < 50
  ORDER BY price
  LIMIT 20
)

SELECT label, cost, status FROM low_price_history
  WHERE label = 'foo';
Result
labelcoststatus
foo9.1354203
foo9.6967503
foo11.8668401
foo12.9706704
foo16.1879102
foo16.4992101


Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8