我正在尝试在 mysql 中的两个 Select 语句之间进行交叉连接。 但是,我收到一条错误消息,提示缺少结尾。 但是,那里不需要结束语句
这是代码
SELECT starts_at, (@row := @row + 1) + start_health_post_id as health_post_id
FROM
(
SELECT DATE_ADD(start_date, INTERVAL start_time MINUTE) AS starts_at
FROM days
CROSS JOIN times
)
slots, (SELECT @row := -1)r
ORDER BY starts_at;
cross join
Select practices.id as practice_id, providers.id as provider_id,
practice_locations.id as practice_location_id
from practices
Inner Join providers on practices.health_post_id = providers.health_post_id
Inner join practice_locations on practices.health_post_id =
practice_locations.health_post_id;
最佳答案
根据MySQL手册:
In MySQL, JOIN, CROSS JOIN, and INNER JOIN are syntactic equivalents (they can replace each other). In standard SQL, they are not equivalent. INNER JOIN is used with an ON clause, CROSS JOIN is used otherwise.
我认为您需要将两个查询括在 ( )
中:
SELECT t1.*, t2.*
FROM
(
SELECT starts_at, (@row := @row + 1) + start_health_post_id as health_post_id
FROM
(
SELECT DATE_ADD(start_date, INTERVAL start_time MINUTE) AS starts_at
FROM days
CROSS JOIN times
)
slots, (SELECT @row := -1) r
ORDER BY starts_at
) as t1
CROSS JOIN
(
Select practices.id as practice_id, providers.id as provider_id,
practice_locations.id as practice_location_id
from practices
Inner Join providers on practices.health_post_id = providers.health_post_id
Inner join practice_locations on practices.health_post_id =
practice_locations.health_post_id
) as t2
ON t1.`t1_field` = t2.`t2_field` -- change it as you need;
关于mysql - 缺少结尾,无法执行mysql交叉连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37994123/