我想知道在SQL样式的QueryDSL中实现此查询的最佳方法,它连接到子查询。我挣扎了一下,但得到它来生成必要的SQL。我想知道是否有任何简化/改进,特别是与我必须创建的三个“路径”有关?例如,根据latestSubQuery定义latestCaseId会很棒。
在下面我的实际查询的简化形式中,我找到了一组记录(遍布#!/bin/bash
EMAILDOMAIN="company.com"
if [[ $2 = 0000000000000000000000000000000000000000 ]] || [[ $3 = 0000000000000000000000000000000000000000 ]]
then
exit 0
fi
# get name and email from git log
EMAILCMD="git log --format="%ce" $3 -1"
EMAIL=$($EMAILCMD)
NAMECMD="git log --format="%cn" $3 -1"
NAME=$($NAMECMD)
# environment variable for the gitolite user (the SSH key)
# echo $GL_USER
# compare email with gitolite user
EXPEMAIL="$GL_USER@$EMAILDOMAIN"
if [ "{$EXPEMAIL,,}" != "{$EMAIL,,}" ]
then
echo "You're committing with the SSH key for '$GL_USER'. That key belongs to $EXPEMAIL."
echo " (You've configured your email as $EMAIL)"
exit 1
fi
# TODO: maybe, if we ever bother installing mail on this box, send an email to some admins if someone is trying to key share
# check the name...
IFS=' ' read -ra NAMEPARTS <<< "${NAME,,}"
PARTCOUNT=0
for PART in "${NAMEPARTS[@]}"
do
PARTCOUNT=$((PARTCOUNT+1))
done
# make sure it's a full name
if (( "$PARTCOUNT" < 2 ))
then
echo "You should put in your full name, $NAME."
echo "If you've really only got one name (like Sting or Madonna), email an admin and we can make an exception for you."
exit 1
fi
exit 0
和ucm
的字段),它们具有每个案例组的最新时间戳。子查询标识每个组的最新时间戳,以便我们可以通过它过滤外部查询。
pcm
答案 0 :(得分:2)
我相信您可以使用.get(<various Path impls>)
的{{1}}方法。我想要的方式是创建PathBuilder
并加入它final PathBuilder<Tuple> latestSubQueryPath = new PathBuilder<>(Tuple.class, "latest")
正在为子查询创建别名。然后,您可以使用.innerJoin(latest, latestSubQueryPath)
访问字段,如下所示:
.get(<various Path impls>)
我没有运行代码,但希望这是正确的方向。如果没有,我明天会看到相关的代码库。
更新:如评论中所述, q.from(ucm)
.join(pcm).on(ucm.id.eq(pcm.id))
.innerJoin(latest, latestSubQueryPath).on(pcm.caseId.eq(latestSubQueryPath.get(pcm2.caseId)))
.where(ucm.lastExtracted.eq(latestSubQueryPath.get(maxLastExtractedDate)));
需要别名。我称之为ucm2.lastExtracted.max()
,并假设它在创建子查询时用于别名maxLastExtractedDate
。