如何通过连接 table 获得不同的值?
How to get Distinct values with joined table?
我打算按输入值过滤,但是当我执行此查询时,我得到了一些重复值!
@Query("SELECT DISTINCT inter FROM Intermediary inter WHERE inter.country=?1 and inter.isGood<>?2 " +
"and inter.company.name like %?3% " +
"or inter.company.identity like %?3% " +
"or inter.company.client like %?3% " +
"order by inter.createdAt DESC")
Page<Intermediary> findAllByCompanyAndSearchValue(Country country, Integer isGood, String searchValue, Pageable pageable);
// Intermediary Entity
{
// ... Other attributes
@ManyToOne(optional = false)
private Company company;
}
// comapny Entity
{
@OneToMany(mappedBy = "company")
@JsonIgnore
private List<Intermediary> intermediaries;
}
尝试在“或”条件周围添加括号,以避免返回满足任何可能的“and/or”组合的行所产生的重复项:
"or (inter.company.identity like %?3% " +
"or inter.company.client like %?3% )" +
我打算按输入值过滤,但是当我执行此查询时,我得到了一些重复值!
@Query("SELECT DISTINCT inter FROM Intermediary inter WHERE inter.country=?1 and inter.isGood<>?2 " +
"and inter.company.name like %?3% " +
"or inter.company.identity like %?3% " +
"or inter.company.client like %?3% " +
"order by inter.createdAt DESC")
Page<Intermediary> findAllByCompanyAndSearchValue(Country country, Integer isGood, String searchValue, Pageable pageable);
// Intermediary Entity
{
// ... Other attributes
@ManyToOne(optional = false)
private Company company;
}
// comapny Entity
{
@OneToMany(mappedBy = "company")
@JsonIgnore
private List<Intermediary> intermediaries;
}
尝试在“或”条件周围添加括号,以避免返回满足任何可能的“and/or”组合的行所产生的重复项:
"or (inter.company.identity like %?3% " +
"or inter.company.client like %?3% )" +