How about query WITH support by QueryBuilder? #6609

Open
opened 2026-01-22 15:35:42 +01:00 by admin · 1 comment
Owner

Originally created by @kulavvy on GitHub (Jan 20, 2021).

Basic example:

WITH regional_sales AS (
        SELECT region, SUM(amount) AS total_sales
        FROM orders
        GROUP BY region
     ), top_regions AS (
        SELECT region
        FROM regional_sales
        WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales)
     )
SELECT region,
       product,
       SUM(quantity) AS product_units,
       SUM(amount) AS product_sales
FROM orders
WHERE region IN (SELECT region FROM top_regions)
GROUP BY region, product;

More info:
https://www.postgresql.org/docs/9.5/queries-with.html

Originally created by @kulavvy on GitHub (Jan 20, 2021). Basic example: ``` WITH regional_sales AS ( SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region ), top_regions AS ( SELECT region FROM regional_sales WHERE total_sales > (SELECT SUM(total_sales)/10 FROM regional_sales) ) SELECT region, product, SUM(quantity) AS product_units, SUM(amount) AS product_sales FROM orders WHERE region IN (SELECT region FROM top_regions) GROUP BY region, product; ``` More info: https://www.postgresql.org/docs/9.5/queries-with.html
Author
Owner

@dbrumann commented on GitHub (Jan 22, 2021):

I don't think MySQL < 8.0 supports WITH. That means Doctrine would need to support an alternative for older MySQL versions, which seems like a lot of work. As far as I can tell it would make more sense to provide this via an extension similar to beberlei/DoctrineExtensions

@dbrumann commented on GitHub (Jan 22, 2021): I don't think MySQL < 8.0 supports `WITH`. That means Doctrine would need to support an alternative for older MySQL versions, which seems like a lot of work. As far as I can tell it would make more sense to provide this via an extension similar to [beberlei/DoctrineExtensions](https://github.com/beberlei/DoctrineExtensions)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6609