我在应用程序中使用queryDsl进行复杂的搜索查询。我是querydsl的新手。我已经开始用下面的代码从一个表(TableA)中获取几行。但我必须在其他表(TableB)中找到具有相同id的person(Count)列表
public static Predicate find(final Long pId)
QPerson qPerson = QPerson.person;
Predicate predicate;
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (pId != null) {
booleanBuilder.or(qPerson.person_no.eq(pId));
}
if (name != null && !name.isEmpty()) {
booleanBuilder.or(qPerson.expiry_dt.eq(name));
}
predicate = booleanBuilder.getValue();
return predicate;
}
为多:
pId name
1001 sampleNameA
1002 sampleNameB
1003 sampleNameC
:表b pId name interests
1001 sampleNameA music
1001 sampleNameA dance
1001 sampleNameA coding
1003 sampleNameC music
1002 sampleNameB dance
1002 sampleNameB coding
我需要得到这样的输出下面的查询
select cnt;* from master_person_table tableA,(select count(*) cnt from tableB WHERE pId = '1002'WHERE pId = '1002'
输出: count pId name
2 1002 sampleNameB
我需要在我的HTML中显示行数(对于id=1002)
有没有人能帮我找到从表b中取出的pId的计数
Thanks in advance
请尝试以下查询:-
1。对于多个pid:-
SELECT COUNT(*) AS COUNT, pId, name FROM TableB GROUP BY pId
2。仅对于选定的pId:-
SELECT COUNT(*) AS COUNT, pId, name FROM TableB WHERE pId = 1002
如果你需要更多的帮助,请告诉我。