skyb писал(а):
Необходимо найти договора которые имеют не заполненые параметры договора, вылетел вот такой запрос, но он не отрабатывает по фильтрации по группам, как поправить?
Код:
SELECT c.title as col1 , cpt18.val as col2
FROM contract AS c
LEFT JOIN contract_parameter_type_2 AS cpt2_9 ON cpt2_9.cid = c.id AND cpt2_9.pid = 9
LEFT JOIN contract_parameter_type_2 AS cpt2_4 ON cpt2_4.cid = c.id AND cpt2_4.pid = 4
LEFT JOIN contract_parameter_type_2 AS cpt2_34 ON cpt2_34.cid = c.id AND cpt2_34.pid = 34
LEFT JOIN contract_parameter_type_phone AS cptp2 ON cptp2.cid = c.id AND cptp2.pid = 2
LEFT JOIN contract_parameter_type_phone AS cptp10 ON cptp10.cid = c.id AND cptp10.pid = 10
LEFT JOIN contract_parameter_type_3 AS cpt3 ON cpt3.cid=c.id AND cpt3.pid = 3
LEFT JOIN contract_parameter_type_1 AS cpt19 ON c.id = cpt19.cid AND cpt19.pid = 19
LEFT JOIN contract_parameter_type_1 AS cpt30 ON c.id = cpt30.cid AND cpt30.pid = 30
LEFT JOIN contract_parameter_type_1 AS cpt18 ON c.id = cpt18.cid AND cpt18.pid = 18
LEFT JOIN contract_parameter_type_1 AS cpt17 ON c.id = cpt17.cid AND cpt17.pid = 17
LEFT JOIN contract_parameter_type_1 AS cpt20 ON c.id = cpt20.cid AND cpt20.pid = 20
LEFT JOIN contract_parameter_type_1 AS cpt25 ON c.id = cpt25.cid AND cpt25.pid = 25
LEFT JOIN contract_parameter_type_1 AS cpt26 ON c.id = cpt26.cid AND cpt26.pid = 26
LEFT JOIN contract_parameter_type_1 AS cpt27 ON c.id = cpt27.cid AND cpt27.pid = 27
LEFT JOIN contract_parameter_type_1 AS cpt28 ON c.id = cpt28.cid AND cpt28.pid = 28
LEFT JOIN contract_parameter_type_1 AS cpt11 ON c.id = cpt11.cid AND cpt11.pid = 11
LEFT JOIN contract_parameter_type_1 AS cpt12 ON c.id = cpt12.cid AND cpt12.pid = 12
LEFT JOIN contract_parameter_type_1 AS cpt13 ON c.id = cpt13.cid AND cpt13.pid = 13
LEFT JOIN contract_parameter_type_1 AS cpt14 ON c.id = cpt14.cid AND cpt14.pid = 14
LEFT JOIN contract_parameter_type_1 AS cpt15 ON c.id = cpt15.cid AND cpt15.pid = 15
LEFT JOIN contract_parameter_type_1 AS cpt16 ON c.id = cpt16.cid AND cpt16.pid = 16
WHERE cpt2_9.address IS NULL OR cpt19.val IS NULL OR cpt30.val IS NULL OR cpt18.val IS NULL
OR cpt17.val IS NULL OR cpt20.val IS NULL OR cpt25.val IS NULL OR cpt26.val IS NULL OR cpt27.val IS NULL
OR cpt28.val IS NULL OR cpt11.val IS NULL OR cpt12.val IS NULL OR cpt13.val IS NULL OR cpt14.val IS NULL
OR cpt15.val IS NULL OR cpt16.val IS NULL OR cpt3.email IS NULL AND gr&$(gr)>0
1.Очень неудобный запрос . Сможете на заглядывая в справочник сказать что такое 20-ый параметр ?

Лучше именовать все, давать имена .
2. Скобок нет, вот и не работает..
Код:
1 + 2 + 3 + 4 + 5 * 6 != (1 + 2 + 3 + 4 + 5 ) * 6