Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Common Table Expressions in MySQL

Common Table Expressions, kurz CTEs, erlauben es, innerhalb einer Abfrage ein temporäres, benanntes Ergebnismenge zu definieren. Sie machen komplexes SQL leichter lesbar und wiederverwendbar.

Syntax

WITH cte_name AS ( SELECT ... ) SELECT * FROM cte_name;

Beispiel

WITH test_cte AS ( SELECT id, order_date, amount FROM sales WHERE amount > 200 ) SELECT * FROM test_cte;
Common Table Expressions in MySQL Common Table Expressions in MySQL