У меня есть вид:
CREATE VIEW UsersCounts AS SELECT
users.id,
users.username,
users.email,
SUM(CASE WHEN orders.id > 0 THEN 1 ELSE 0 END) as orders_all,
SUM(CASE WHEN orders.status='ACTIVE' THEN 1 ELSE 0 END) as orders_active,
SUM(CASE WHEN orders.status='RETURNED' THEN 1 ELSE 0 END) as orders_returned
FROM users
INNER JOIN orders ON
users.email = orders.email
GROUP BY users.id
Результат:
id | username | email | orders_all | orders_active | orders_returned
Как я могу установить Users.customer_status = "VIP"'
, где orders_active > 5
?