我是一名技术新手,拥有一个带有.MDB(MS-Access)数据库的ColdFusion网站,该数据库由我的托管服务新转换为MySQL。在转换为MySQL之后,过去完美工作多年的查询不再有效,并抛出错误消息"每个派生表必须有自己的别名"。
作为帮助,这是查询的作用 - 并且到目前为止完全完成:我有一个会员数据库。每个成员最多有四个电子邮件地址,因此每个记录的数据库中有四列,每个电子邮件地址与电子邮件服务提供商域(Comcast.net,gmail.com,aol.com等)相关联。我使用查询结果单独列出所有电子邮件域,其中包含与每个电子邮件地址关联的成员电子邮件地址总数(Comcast.net 12,gmail.com 26,aol.com 13等)。
我需要在此查询中进行最低限度的修改才能使其与MySQL一起使用?谢谢你的帮助!
<cfquery name="cfqGetEmailServiceProviderDomains" datasource="membership_database">
SELECT email_service_provider, COUNT(email_service_provider) AS Instances
FROM
(
SELECT MID(email_address1, INSTR(email_address1, '@') + 1) AS email_service_provider
FROM tblMembers
WHERE email_address1_active = 1
AND email_address1 IS NOT NULL
UNION ALL
SELECT MID(email_address2, INSTR(email_address2, '@') + 1) AS email_service_provider
FROM tblMembers
WHERE email_address2_active = 1
AND email_address2 IS NOT NULL
UNION ALL
SELECT MID(email_address3, INSTR(email_address3, '@') + 1) AS email_service_provider
FROM tblMembers
WHERE email_address3_active = 1
AND email_address3 IS NOT NULL
UNION ALL
SELECT MID(email_address4, INSTR(email_address4, '@') + 1) AS email_service_provider
FROM tblMembers
WHERE email_address4_active = 1
AND email_address4 IS NOT NULL
)
GROUP BY email_service_provider
ORDER BY email_service_provider ASC
</cfquery>
答案 0 :(得分:0)
尝试在表格中添加别名
SELECT ...
FROM (
...
) table_alias
GROUP BY ...
ORDER BY ...