SELECT DISTINCT g.* FROM epms_group g LEFT JOIN epms_member m ON m.saas_group_id = g.saas_group_Id LEFT JOIN epms_visit_country v ON v.saas_group_id = g.saas_group_Id WHERE 1 = 1 <if test="status !=null and status != ''"> and g.status in #{status} </if> order by create_date desc 前端传到后端的状态是多个 比如一,二,三,四, 这里的sql该怎么写
时间: 2024-03-02 18:51:53 浏览: 66
SQLyuju.rar_sql_sql查询 大全_查询 SQL
你的 SQL 可以这样写:
```
SELECT DISTINCT g.*
FROM epms_group g
LEFT JOIN epms_member m ON m.saas_group_id = g.saas_group_Id
LEFT JOIN epms_visit_country v ON v.saas_group_id = g.saas_group_Id
WHERE 1 = 1
AND g.status IN (
<foreach collection="status.split(',')" item="item" separator=",">
#{item}
</foreach>
)
ORDER BY create_date DESC
```
这里使用了 MyBatis 的 foreach 标签,将前端传递过来的状态字符串按照逗号分隔为多个参数,然后在 SQL 中进行 IN 查询。
阅读全文