好的,在这个问题上我需要一些重要的帮助。这就是我需要做的事情。它需要在出勤表中获取DKP_Change列的总和

 SELECT SUM(a.DKP_Change) FROM Attendance AS a GROUP BY Name


从字符表中添加初始DKP的值

 SELECT b.Inital_DKP FROM Characters AS b GROUP BY Name


减去突袭掉落的塔布费用总和

 SELECT SUM(c.Cost) FROM Raid_Drops AS c GROUP BY Name


我对VIEWS的想法是完全陌生的,我不确定从哪里开始,视图的名称应该是DKP,列应该是Name和Total_DKP,其中总dkp是从select语句上方计算得出的。

这是所有3个表的创建。

CREATE TABLE `Attendance` (
 `Date` date NOT NULL,
 `Name` varchar(20) NOT NULL,
 `Hours` int(11) NOT NULL,
 `Penalty` float NOT NULL,
 `Rank` set('Raider','Core','Elite') NOT NULL,
 `Rate` int(11) NOT NULL,
 `DKP_Change` float NOT NULL,
 `RecordNumber` int(11) NOT NULL AUTO_INCREMENT,
 PRIMARY KEY (`RecordNumber`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=latin1

CREATE TABLE `Characters` (
 `ID` int(11) NOT NULL AUTO_INCREMENT,
 `Name` varchar(25) NOT NULL,
 `Class` varchar(25) NOT NULL,
 `Spec` varchar(25) NOT NULL,
 `Position` set('Healer','Tank','DPS') NOT NULL COMMENT 'Healer, Tank, or DPS',
 `Usable` set('Cloth','Mail','Plate') NOT NULL COMMENT 'Type of Usable Armor? Cloth,        Mail, Or Plate',
 `Primary Stat` set('Agility','Strength','Intellect','Healer','Tank') NOT NULL COMMENT     'Used for Sorting Only(ie dps trinket with agility strength dps not eligible)',
 `Initial_DKP` int(11) NOT NULL COMMENT 'DKP given at the start of current tier.',
 `Total_DKP` int(11) NOT NULL COMMENT 'Huge Complicated Mess.',
 PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

CREATE TABLE `Raid_Drops` (
 `Record Number` int(11) NOT NULL,
 `Date` date NOT NULL,
 `Name of Item` varchar(25) NOT NULL,
 `Item Slot` enum('Main Hand','Off Hand','Head','Neck','Shoulder','Back','Chest','Wrist','Hands','Waist','Legs','Feet','Ring 1','Ring 2','Trinket 1','Trinket 2') NOT NULL,
 `Player_Name` varchar(25) NOT NULL,
 `Cost` float NOT NULL,
 PRIMARY KEY (`Record Number`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

最佳答案

你可以


将三个表联接到一个子选择中,并按Name分组
对每个子选择的结果执行计算


我唯一不清楚的唯一部分是Characters中的名称是否唯一。如果是,则可以删除分组依据。如果不是这样,AVG可能会给您带来意想不到的结果。

SQL语句

SELECT sumA
       , initialB
       , sumC
       , sumA + initialB - sumC
       , a.Name
FROM   (
         SELECT Name, SUM(DKP_Change) AS sumA
         FROM Attendance
         GROUP BY Name
       ) AS a
       INNER JOIN (
         SELECT Name, Inital_DKP AS initialB
         FROM Characters
       ) AS b ON a.Name = b.Name
       INNER JOIN (
         SELECT Name, SUM(Cost) AS sumC
         FROM Raid_Drops
         GROUP BY Name
       ) AS c ON c.Name = b.Name

09-07 23:40