0

让我们开始吧。

这将返回正确的结果:

SELECT sum(w.weight * w.repetitions)
FROM workout_exercise_logs w
JOIN workout_logs wo ON `w`.`workoutLogID`=`wo`.`workoutLogID`
JOIN workouts wor ON `wo`.`workoutID`=`wor`.`workoutID`
WHERE w.weightType=1 and `wor`.`userID`=34

但是当我添加时+ w.weight * w.seconds / 3,我得到了一个NULL结果:

SELECT sum(w.weight * w.repetitions + w.weight * w.seconds / 3)
FROM workout_exercise_logs w
JOIN workout_logs wo ON `w`.`workoutLogID`=`wo`.`workoutLogID`
JOIN workouts wor ON `wo`.`workoutID`=`wor`.`workoutID`
WHERE w.weightType=1 and `wor`.`userID`=34

表达式有什么问题,我该如何解决?谢谢!

4

1 回答 1

2

一个问题,你是否真的需要这个字段可以为空(或任何相关的字段):秒?

如果这是一个要求,您需要将这些可为空的字段合并为零:

SELECT sum(
      w.weight * w.repetitions 
      + w.weight * coalesce(w.seconds,0) / 3)
FROM workout_exercise_logs w
JOIN workout_logs wo ON `w`.`workoutLogID`=`wo`.`workoutLogID`
JOIN workouts wor ON `wo`.`workoutID`=`wor`.`workoutID`
WHERE w.weightType=1 and `wor`.`userID`=34
于 2012-05-16T02:01:37.283 回答