仅显示具有最新日期加入视图的行

时间:2018-09-07 16:24:52

标签: mysql view

我正在尝试运行此视图。

select `AM`.`athleteID` AS `athleteid`,
       `AM`.`maxLift` AS `maxlift`,
       `AM`.`dateofmax` AS `dateofmax`,
       `TP`.`date` AS `date`,
       `TP`.`teamID` AS `teamID`,
       `TSP`.`trainingSessionProgramID` AS `trainingSessionProgramID`,
       `TSP`.`trainingSessionKey` AS `trainingSessionKey`,
       `E`.`exerciseName` AS `exerciseName`,
       `RS`.`repScheme` AS `repScheme`,
       `RS`.`percentage` AS `percentage`,
       `TSP`.`exerciseID` AS `exerciseID`,
       `TSP`.`repSchemeID` AS `repSchemeID` 
from ((((`dutchIron`.`tblExercises` `E` 
         left join `dutchIron`.`tblTrainingSessionProgramming` `TSP` 
                    on((`E`.`exerciseID` = `TSP`.`exerciseID`))) 
         left join `dutchIron`.`tblRepSchemes` `RS` 
                   on((`RS`.`repSchemeID` = `TSP`.`repSchemeID`))) 
         left join `dutchIron`.`tblProgramming` `TP` 
                   on((`TP`.`trainingSessionKey` = `TSP`.`trainingSessionKey`))) 
         left join `dutchIron`.`tblAthleteMaxs` `AM` 
                   on((`AM`.`exerciseID` = `E`.`exerciseID`)))

我正在tblAthleteMaxs中记录最大举升重量。但是,当我运行查询时,将获得多组行,具体取决于表中有多少最大权重值(AM.maxLift)。理想情况下,我只想选择最新的最大权重值(AM.dateofmax)并让视图返回那些行。有人可以帮忙吗?提前谢谢了。

这是当前返回的内容。理想情况下,我只想将maxlift设置为500,因为它是一个较晚的日期。现在,它还包括所有345行。

imageofcurrentview

我已经审查了重复的帖子,但对我来说都没有意义。我只需要具有最新dateofmax的所有行。执行max(dateofmax)不起作用,因为它只会提取一条记录。任何援助将不胜感激。

0 个答案:

没有答案