将 SQL 脚本转换为 Access [关闭]
Posted
技术标签:
【中文标题】将 SQL 脚本转换为 Access [关闭]【英文标题】:Convert SQL script to Access [closed] 【发布时间】:2019-01-28 16:01:09 【问题描述】:我知道 access 和 sql 是有区别的。我正在尝试将此脚本转换为 Access,但无法使其正常工作。
SELECT TOP 20 g.Title, COALESCE(m1.Pageviews, 0) + COALESCE(m2.Pageviews, 0) + COALESCE(m3.Pageviews,0) AS Total_Pageviews,
COALESCE(m1.Pageviews, 0) AS Month1,
COALESCE(m2.Pageviews, 0) AS Month2,
COALESCE(m3.Pageviews, 0) AS Month3
FROM (SELECT URL, Title FROM dbo_vw_GoodURLs WHERE URL LIKE '/blog*') g
LEFT OUTER JOIN dbo_analytics_history m1
ON g.URL = m1.URL AND m1.URL LIKE '/blog*' AND m1.Report_Month = 10
LEFT OUTER JOIN dbo_analytics_history m2
ON g.URL = m2.URL AND m2.URL LIKE '/blog*' AND m2.Report_Month = 11
LEFT OUTER JOIN dbo_analytics_history m3
ON g.URL = m3.URL AND m3.URL LIKE '/blog*' AND m3.Report_Month = 12
GROUP BY g.Title, m1.Pageviews, m2.Pageviews, m3.Pageviews
ORDER BY COALESCE(m1.Pageviews, 0) + COALESCE(m2.Pageviews, 0) + COALESCE(m3.Pageviews, 0) DESC;
【问题讨论】:
我知道 access 和 sql 有区别。 ... MS Access 是一个数据库而不是运行 SQL。所以这还不清楚。 【参考方案1】:在MS-Acess
中,您需要括号来评估多个JOIN
s:
SELECT TOP 20 g.Title,
IIF(m1.Pageviews IS NULL, 0, m1.Pageviews) +
IIF(m2.Pageviews IS NULL, 0, m2.Pageviews) +
IIF(m3.Pageviews IS NULL, 0, m3.Pageviews) AS Total_Pageviews,
. . .
FROM ((SELECT URL, Title
FROM dbo_vw_GoodURLs AS vw LEFT OUTER JOIN
dbo_analytics_history m1
ON g.URL = m1.URL AND m1.URL LIKE '%blog%' AND m1.Report_Month = 10
) LEFT OUTER JOIN dbo_analytics_history AS m2
ON g.URL = m2.URL AND m2.URL LIKE '%blog%' AND m2.Report_Month = 11
) LEFT OUTER JOIN dbo_analytics_history m3
ON g.URL = m3.URL AND m3.URL LIKE '/blog*' AND m3.Report_Month = 12
WHERE vw.URL LIKE '%blog%'
GROUP BY . . . ;
【讨论】:
以上是关于将 SQL 脚本转换为 Access [关闭]的主要内容,如果未能解决你的问题,请参考以下文章