我有两个表:一个名为issues
,另一个名为time_entries
,其中id_issue
为外键。我根据id_issue
列进行了INNER JOIN。
SELECT
SUM(time_entries.hours)
, issues.id
, time_entries.created_on
, time_entries.updated_on
, issues.`estimated_hours`
, issues.`done_ratio`
FROM
issues
INNER JOIN
time_entries
ON
issues.id = time_entries.issue_id
WHERE
issues.project_id = 2
GROUP BY
issues.id
我将此查询放在本机查询中:
Query query = (Query) this.em.createNativeQuery(
"SELECT " +
" SUM(time_entries.hours) " +
" , issues.id " +
" , issues.estimated_hours" +
" , issues.done_ratio" +
"FROM " +
" issues " +
"INNER JOIN " +
" time_entries " +
"ON " +
" issues.id = time_entries.issue_id " +
"WHERE " +
" issues.project_id = 2 " +
"GROUP BY " +
" issues.id");
List<?> result = query.getResultList();
当我执行这两行Java代码时,我得不到与在MySQL控制台中执行此查询相同的结果,但我在跟踪中得到了相同的查询。