对于我的网站(PHP / MySql),我需要一些管理信息。 在测试期间,我能够在MS Access中生成一个有效的查询。
子查询'qryUnion':
SELECT Mailadres, Registrationdate FROM tbl-A
UNION
SELECT Mailadres, Registrationdate FROM tbl-B;
主要查询:
SELECT Year([Maildate]) & '-' & Month([Maildate]) AS MonthMailed, Count(tbl-C.Mailadres) AS Prospects, Count(qryUnion.Mailadres) AS Members
FROM tbl-C LEFT JOIN qryUnion ON tbl-C.Mailadres = qryUnion.Mailadres
GROUP BY Year([Maildate]) & '-' & Month([Maildate]);
我想将其转换为MySql数据库。我尝试使用别名或临时表,但我无法获得正在运行的代码。有人知道怎么做吗?
答案 0 :(得分:0)
将联合移动到内联视图,如下所示。
您可能还必须使用CONCAT()函数替换字符串添加项,并将int转换为CHAR。我不肯定我的语法正确,但这可能很接近。
SELECT concat(cast(Year(`Maildate`) AS CHAR),'-',CAST(Month(`Maildate`) AS CHAR) AS MonthMailed,
Count(tbl-C.Mailadres) AS Prospects, Count(qryUnion.Mailadres) AS Members
FROM tbl-C
LEFT JOIN
(SELECT Mailadres, Registrationdate FROM tbl-A
UNION
SELECT Mailadres, Registrationdate FROM tbl-B) qryUnion
ON tbl-C.Mailadres = qryUnion.Mailadres
GROUP BY concat(cast(Year(`Maildate`) AS CHAR),'-',CAST(Month(`Maildate`) AS CHAR);
已更正)在年度评估的错误位置并转换为char。选择和分组。