-1

我似乎遇到了查询语法错误,但似乎无法隔离它。我正在使用 MS Access,当我运行查询时,在 FROM 子句中出现语法错误。

我有两个表,它们是一对多的关系:

表 1 称为(客户),具有以下字段:

ID
FirstName

名为 (tblservice) 的表 2 包含以下字段:

serviceID
Timing
Total
customerID   <-Foreign Key

第一个查询:

select c.id, c.firstname, avg(s.Total) / (select count(id) from customer) as LifetimeValue
from tblservice as s join customer as c on s.id = c.id
group by s.id

第二次查询(30天跨度):

select c.id, c.firstname, avg(s.Total) / (select count(id) from customer) as LifetimeValue
from tblservice as s join customer as c on s.id = c.id
where (s.Timing)>=DateAdd("d",-30,Date())
group by s.id
4

2 回答 2

1

试试这个:

select c.id, c.firstname, avg(s.Total) / count(c.id) as LifetimeValue
from tblservice as s inner join customer as c on s.id = c.id
group by c.id, c.firstname

select c.id, c.firstname, avg(s.Total) / count(c.id) as LifetimeValue
from tblservice as s inner join customer as c on s.id = c.id
where (s.Timing)>=DateAdd("d",-30,Date())
group by c.id, c.firstname

您不能选择c.id并且c.firstname除非您按它们分组。而且您可以使用count(c.id),因为您已经按c.id. 虽然我没有在 MS Access 中使用 SQL。所以我不是100%肯定。试试看。

于 2012-06-01T04:30:04.640 回答
1

MS Access 可能会要求您使用INNER JOIN,而不仅仅是JOIN.

于 2012-06-01T04:44:46.983 回答