-- Works fine with MySQL 8.0.2 Alpha	=>	Resultset 1
-- Doesn't work with MariaDB 10.2.7		=>	Message: SQL Error (1146): Table 'test.cte1' doesn't exist

USE test;

SET @sql_query = "

	CREATE OR REPLACE VIEW cte_test AS

		WITH	cte1	AS ( SELECT 1 )
	
		,		cte2	AS ( SELECT * FROM cte1 )

		SELECT * FROM cte2;

";
	
PREPARE stmt FROM @sql_query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SELECT * FROM `CTE_Test`;