需要实现Filter,条件spring数据

时间:2018-05-28 19:26:57

标签: sql spring spring-mvc spring-data spring-data-jpa

我有一个表User,其中包含RoleCity的集合。

我需要实现像 /?cities = LA,Berlin& roles = Admin 这样的过滤器逻辑,它返回具有{LA and Berlin and other if it has}和角色{Admin}的用户

SELECT * FROM user

LEFT JOIN user_city
ON user.id = user_city.user_id
LEFT JOIN city
ON city.id = user_city.city_id

WHERE city.name in ('LA','Berlin')  
GROUP BY 
HAVING COUNT(*) = 2;

它适用于一个标准如何制作两个或更多? 我需要在标准弹簧数据上制作它,但最好先了解它在sql中是如何工作的。

1 个答案:

答案 0 :(得分:0)

SELECT *
FROM user

LEFT JOIN user_city
ON user.id = user_city.user_id
LEFT JOIN city
ON city.id = user_city.city_id

WHERE city.name in ('LA','Berlin')  
AND roles= 'Admin'
GROUP BY 
HAVING COUNT(*) = 2;