ERROR 8118 (HY000): Failed to build executor

可以用 CTE 试试

https://docs.pingcap.com/zh/tidb/stable/sql-statement-with#示例