我有多个SQL语句需要通过Eloquent运行。它们看起来像这样:
CREATE TEMPORARY TABLE cars
AS (SELECT cars.id, cars.ip_address
FROM cars
JOIN colors ON colors.ip_address = cars.ip_address);
CREATE TEMPORARY TABLE boats
AS (SELECT ip_address, MIN(id) AS id
FROM colors
GROUP BY ip_address);
CREATE TEMPORARY TABLE rvs
AS (SELECT rvs.id, rvs.ip_address
FROM rvs
LEFT JOIN colors ON colors.id = rvs.id
WHERE colors.id IS NULL);
/* Do things with temp tables here */
我需要在一个连接会话中运行所有这些语句,因为它们使用临时表。我尝试过使用
DB::statement()
,但在第二个语句操作开始时出错,并且使用 DB::unprepared()
似乎不运行任何操作。有没有一种使用 Eloquent 运行多个原始语句的方法?