如何使用子选择查询或MySQL中的任何其他方法重写此查询?
我正在使用3张桌子:
SELECT i.resp_id as id
, Count(1)
FROM int_result i
JOIN response_set rs on i.response_set_id = rs.id
JOIN cx_store_child cbu on rs.cx_business_unit_id = cbu.child_bu_id
AND cbu.business_unit_id = 30850
AND rs.survey_id IN (5550512,5550516,5550521,5550520,5590351,5590384,5679615,5679646,5691634,5699259,5699266,5699270)
AND i.q_id IN (52603091,52251250,52250724,52251333,52919541,52920117,54409178,54409806,54625102,54738933,54739117,54739221)
AND rs.t >= '2017-08-30 00:00:00'
AND rs.t <= '2017-09-30 00:00:00'
GROUP BY rs.cx_business_unit_id, i.a_id;
答案 0 :(得分:0)
也许是吗?
SELECT i.resp_id as id
, Count(1)
FROM int_result i, response_set rs, cx_store_child cbu
WHERE i.response_set_id = rs.id
AND rs.cx_business_unit_id = cbu.child_bu_id
AND cbu.business_unit_id = 30850
AND rs.survey_id IN (5550512,5550516,5550521,5550520,5590351,5590384,5679615,5679646,5691634,5699259,5699266,5699270)
AND i.q_id IN (52603091,52251250,52250724,52251333,52919541,52920117,54409178,54409806,54625102,54738933,54739117,54739221)
AND rs.t >= '2017-08-30 00:00:00'
AND rs.t <= '2017-09-30 00:00:00'
ORDER BY rs.cx_business_unit_id, i.a_id;