如何连续使用多个IN(数组)

时间:2016-04-26 13:53:01

标签: mysql

Mysql从三个IN()中选择所有情况我只需要选择:3,204,68 | 3,204,69 | 49,230,2 | 49,230,3

SELECT * FROM rates r
WHERE 1 = 1
AND r.active = 1
AND r.client_id IN (3,3,49,49)
AND r.mcc       IN (204,204,230,230)
AND r.mnc       IN (68,69,2,3)

不是那样的:

enter image description here

如何做到这一点:client_id = 3 AND mcc = 204 AND mnc = 68client_id = 3 AND mcc = 204 AND mnc = 69 泰语全部用于client_id = 3

3 个答案:

答案 0 :(得分:0)

这样可行,但它专门用于您提供给我的数据,如果您想让它动态运行,您必须生成查询:

SELECT *
FROM rates r
WHERE 1 = 1
AND r.active = 1
AND ((r.client_id = 3 AND r.mcc = 204 AND r.mnc = 68)
     OR (r.client_id = 3 AND r.mcc = 204 AND r.mnc = 69)
     OR (r.client_id = 49 AND r.mcc = 230 AND r.mnc = 2)
     OR (r.client_id = 49 AND r.mcc = 230 AND r.mnc = 3))

答案 1 :(得分:0)

您可以使用AND和OR的基本组合,而不需要任何IN

SELECT *
FROM
rates r

WHERE
1 = 1
AND r.active                               = 1
AND ((r.client_id = 3 AND r.mcc = 204 AND r.mnc = 68) OR (r.client ...)

答案 2 :(得分:0)

使用“concat_ws”

eclipse.ini