将MySQL代码转换为Access:GROUP_CONCAT和三重JOIN
作者:互联网
我很难将一段MySQL代码翻译成Access.
我正在尝试使用Sakila(MySQL)数据库中的一个查询来处理我正在进行的Access项目.
首先,GROUP_CONCAT函数根本不起作用.在一些谷歌搜索后,我发现Access不支持此功能,但我找不到可行的替代方案.然而,CONCAT可以被一些”操作符所取代.
然后是三重LEFT JOIN,它不断返回缺少的操作错误.我找到了一篇博客文章,解释了一系列括号如何帮助,但这导致了更多的麻烦,并促使我删除括号,之后它丢失了更多的操作符错误.
此外,SEPARATOR似乎也不被接受,但这可能是由于GROUP_CONCAT无法正常运行.
有没有人愿意让我朝着正确的方向前进?我一直在努力解决这个问题太久了.
SELECT
a.actor_id,
a.first_name,
a.last_name,
GROUP_CONCAT(DISTINCT CONCAT(c.name, ': ',
(SELECT GROUP_CONCAT(f.title ORDER BY f.title SEPARATOR ', ')
FROM film f
INNER JOIN film_category fc
ON f.film_id = fc.film_id
INNER JOIN film_actor fa
ON f.film_id = fa.film_id
WHERE fc.category_id = c.category_id
AND fa.actor_id = a.actor_id
)
)
ORDER BY c.name SEPARATOR '; ')
AS film_info
FROM
actor AS a
LEFT JOIN film_actor AS fa ON a.actor_id = fa.actor_id
LEFT JOIN film_category AS fc ON fa.film_id = fc.film_id
LEFT JOIN category AS c ON fc.category_id = c.category_id
GROUP BY a.actor_id, a.first_name, a.last_name
解决方法:
MySQL GROUP_CONCAT()函数最常用的Access替代方案是Allen Browne的ConcatRelated()函数,可用于here.
至于JOIN周围的括号,是的,Access SQL很挑剔.代替
FROM
actor AS a
LEFT JOIN film_actor AS fa ON a.actor_id = fa.actor_id
LEFT JOIN film_category AS fc ON fa.film_id = fc.film_id
LEFT JOIN category AS c ON fc.category_id = c.category_id
尝试
FROM
(
(
actor AS a
LEFT JOIN
film_actor AS fa
ON a.actor_id = fa.actor_id
)
LEFT JOIN
film_category AS fc
ON fa.film_id = fc.film_id
)
LEFT JOIN
category AS c
ON fc.category_id = c.category_id
标签:mysql,ms-access,group-concat 来源: https://codeday.me/bug/20190929/1831165.html