表格1:
create table Program_T
(AccountName varchar(150) not null unique,
ProgramID int not null,
Revenue int,
Advocates int,
Shares int,
Conversions int,
Impressions int,
LaunchDate date,
CSMID int not null,
constraint Program_PK primary key (AccountName, CSMID),
constraint Program_FK1 foreign key (AccountName) references Account_T(AccountName),
constraint Program_FK2 foreign key (CSMID) references CSM_T(CSMID));
表#2:
create table Account_T
(AccountName varchar(150) not null unique,
Health varchar(10) not null,
EcommercePlatform varchar(50),
CSMID int not null,
Industry varchar(50),
Amount int not null,
constraint Accounts_PK primary key (AccountName),
constraint Accounts_FK foreign key (CSMID) references CSM_T(CSMID));
我正在尝试编写一个查询,它将为我们提供每个电子商务平台订购的平均收入。
到目前为止我有....
Select Revenue, EcommercePlatform
From Program_T, Account_T
Where Avg(Revenue)
Order by EcommercePlatform;
但我收到的错误是:
无效使用组功能“但我甚至没有使用组功能。
请指教
为此,代码应如下所示:
Select Avg(Revenue), EcommercePlatform
From Program_T inner join Account_T on Program_T.AccountName=Account_T.AccountName
group by EcommercePlatform;
这应该工作得很好。
我想你想要:
select a.EcommercePlatform, Avg(p.Revenue)
grom Program_T p join
Account_T a
using (accountName)
group by a.EcommercePlatform;
笔记:
JOIN
语法。FROM
条款中使用逗号。select
子句中,而不是where
子句。