所以基本上我有这个表Class_Sumations
,我需要用一些方法来计算其他表格中NumberofClassesTaken
和AmountPaid
列的总和...最后一张表中的尊重列。
NumberofClassesTaken
列只会汇总客户所用的所有类并给出一个数字。 AmountPaid
列将汇总给定客户在课程上花费的所有金额,并给出总计。
因此,例如,客户1可以参加2个瑜伽课程并支付200美元,因此NumberofClassesTaken
将显示2,AmountPaid
列将显示100。
我尝试了SELECT
和总和,但我总是得到
错误代码1064,SQL状态42000:您的SQL语法错误
回到我身边。
有人能指出我在正确的方向吗? (请记住,我对此比较陌生,所以,如果你有一些文件证明你的建议也会很棒)
PS:我省略了TRAINER表,因为它与俱乐部类分开,因此你可以忽略CLUB_CLASSES中的那个外键。
CREATE TABLE CLIENT(
ClientNumber INT(50) NOT NULL,
ClientLastName VARCHAR(50) NOT NULL,
ClientFirstName VARCHAR(50) NOT NULL,
ClientPhone VARCHAR(50) NOT NULL,
ClientEmail VARCHAR(50) NOT NULL,
ClientState VARCHAR(50) NOT NULL,
ClientCity VARCHAR(50) NOT NULL,
ClientStreet VARCHAR(50) NOT NULL,
ClientAddress VARCHAR(50) NOT NULL,
ClientZipCode INT NOT NULL,
PRIMARY KEY (ClientNumber));
INSERT INTO CLIENT
VALUES
('1','Marget','Michael','7703399207','MM@gmail.com',
'Kentucky','Merlin','Wending Way','312 Wending Way','30144');
INSERT INTO CLIENT
VALUES
('2','Squarepants','Spongebob','7701274532','SS@gmail.com',
'Kentucky','Merlin','Pineapple Under the Sea Way',
'856 Pineapple Under the Seas Way','30122');
CREATE TABLE CLUB_CLASSES(
ClassID INT(50) NOT NULL,
InstructorTrainerID INT(50) NOT NULL,
ClassName VARCHAR(50) NOT NULL,
ClassStartDate date NOT NULL,
ClassEndDate date NOT NULL,
ClassCost VARCHAR(50) NOT NULL,
PRIMARY KEY(ClassID),
FOREIGN KEY (InstructorTrainerID) REFERENCES TRAINER(TrainerID));
INSERT INTO CLUB_CLASSES
VALUES ('3501','1154','Yoga','1/3/13','1/5/13','100');
INSERT INTO CLUB_CLASSES
VALUES ('3502','2856','Pillate','1/3/13','2/5/13','50');
CREATE TABLE CLASS_SUMMATIONS(
ClassID INT(50) NOT NULL,
ClientID INT(50) NOT NULL,
NumberofClassesTaken VARCHAR(50) NOT NULL,
AmountPaid VARCHAR(50) NOT NULL,
PRIMARY KEY(ClassID, ClientNumber),
FOREIGN KEY(ClientNumber) REFERENCES CLIENT(ClientNumber));
INSERT INTO CLIENT_SUMMATIONS (
'3501','1',
'SELECT SUM(CLUB_CLASSES.ClassID','SELECT SUM(CLUB_CLASSES.ClassCost)');
INSERT INTO CLIENT_SUMMATIONS('3502','2','xxx','xxxx');