Select U.Field
from (
SELECT Field
FROM PhonesTBL
Inner join HistoryTBL on PhonesTBL.Field=Field.PhoneID
group by Field
Order By Count(*) Desc
Union All
Select Field
From HistoryTBL Inner Join UsersTBL on HistoryTBL.UserID = UsersTBL.UserID
Where UBirthday Between #date1# and #date2#
Group By Field
Order By Count(*) Desc) u
Group by u.Field
having Count(*) > 1
以下查询返回标题中的异常,我不知道我在做什么错,因为我在其他表上使用相同的union all方法,并且可以正常工作,请帮我:)
答案 0 :(得分:0)
一些建议:
order by
以下内容可能会满足您的要求:
select U.Field
from (select PhonesTBL.Field
from PhonesTBL inner join
HistoryTBL
on PhonesTBL.Field = Field.PhoneID
group by PhonesTBL.Field
union all
select UsersTBL.Field
from HistoryTBL Inner Join
UsersTBL
on HistoryTBL.UserID = UsersTBL.UserID
where UsersTBL.UBirthday Between #date1# and #date2#
group by UsersTBL.Field
) as u
group by u.Field
having count(*) > 1;
如果有一个更简单的查询来完成所需的操作,我不会感到惊讶-但您无需指定具体内容。如果您想调查此查询的替代方法,则可以提出另一个问题,并提供示例数据,所需结果,解释以及尝试解决的方法。