嗨,我正在尝试创建选择,它将按月计算取件表中的取件。Select 将用于在.NET 上编写的网站。
报告将如下所示
我有 3 张桌子
create table Agency
(
AgencyID int not null IDENTITY,
AgencyName varchar (100)not null,
CeresNo VARCHAR(7),
AgencyCode varchar (16) not null,
Active bit,
CensusDist varchar(50) ,
GroupCode varchar (10),
Primary Key (AgencyID),
FOREIGN KEY (CensusDist) REFERENCES AgencyCensus(CensusDist),
FOREIGN KEY (GroupCode) REFERENCES AgencyGroup (GroupCode)
);
客户表
create table Clients
(
ClientID int not null IDENTITY (9000,1),
AgencyID int not null,
AppDate date not null,
CertifiedDate date ,
Primary Key (ClientID),
FOREIGN KEY (AgencyID) REFERENCES Agency(AgencyID),
);
和取货台
create table Pickup
(
PickupID int IDENTITY,
ClientID int ,
PickupDate date ,
PickupProxy varchar (200) ,
PickupHispanic bit default 0,
EthnCode varchar(5) ,
CategCode varchar (2) ,
AgencyID int,
Primary Key (PickupID),
FOREIGN KEY (ClientID) REFERENCES Clients (ClientID)
);
到目前为止我有这个声明
select
[Agency]= (select AgencyName from agency),
[Jan] = (select count(pickupid) from pickup where PickupDate between '2012-01-01' and '2012-01-31' group by AgencyID),
[FEB] = (select count(pickupid) from pickup where PickupDate between '2012-02-01' and '2012-02-29' group by AgencyID )
选择尚未完成,可能应该重写,但我不知道如何:( 它抛出错误
消息 512,级别 16,状态 1,第 1 行
子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
还有一个问题是我不知道如何在当前年份的皮卡表中查看记录。因为我认为将使用网站的人将无法在选择中更改日期:) 此外,由于某种原因,函数 AVG 无法计算正确的平均值并且不想按组进行计算。请帮忙!