14 lines
433 B
MySQL
14 lines
433 B
MySQL
|
|
||
|
UPDATE vn.client c
|
||
|
JOIN (
|
||
|
SELECT c.id, COUNT(DISTINCT co.id) > 1 hasDifferentCountries
|
||
|
FROM vn.client c
|
||
|
JOIN vn.`address` a ON a.clientFk = c.id
|
||
|
JOIN vn.province p ON p.id = a.provinceFk
|
||
|
JOIN vn.country co ON co.id = p.countryFk
|
||
|
WHERE NOT c.hasToInvoiceByAddress
|
||
|
AND a.isActive
|
||
|
GROUP BY a.clientFk
|
||
|
HAVING hasDifferentCountries
|
||
|
)sub ON sub.id = c.id
|
||
|
SET c.hasToInvoiceByAddress = TRUE;
|