【发布时间】:2019-07-03 17:38:30
【问题描述】:
你能帮我把这个 SQL 语句转换成 CriteriaBuilder 语句吗?我遇到的问题是 INNER JOIN 语句。
SELECT th.id, th.date, th.exercise_id
FROM traininghistory th
INNER JOIN (
SELECT exercise_id, MAX(date) as maxdate
FROM traininghistory
group by exercise_id
) AS tm on tm.exercise_id = th.exercise_id AND th.date = tm.maxdate
WHERE th.accountid = :accountId
@Entity
public class TrainingHistory {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@NotNull
public Long id;
public Long accountId;
@ManyToOne
public Exercise exercise;
public Date dateDone = new Date();
public WellBeing wellBeing;
public int weight;
public int repetitions;
public int duration;
}
【问题讨论】:
-
请您发布受影响的实体。没有任何实体是不可能提出任何建议的。
标签: java postgresql jpa