SELECT "t".*,
(SELECT COUNT(*) FROM "user_archive_view" WHERE user_tariff_id = t.id) AS "count_archive"
FROM "user_tariff" "t"
HAVING (SELECT COUNT(*) FROM "user_archive_view" WHERE user_tariff_id = t.id) = '100';
SELECT *
FROM wp_postmeta
WHERE post_id in (
SELECT id FROM wp_posts p
LEFT JOIN wp_term_relationships r ON p.ID =r.object_id
LEFT JOIN wp_term_taxonomy t ON r.term_taxonomy_id = t.term_taxonomy_id
WHERE p.post_type = 'water'
AND t.taxonomy = 'menu'
AND t.term_id = 22
)
AND meta_value LIKE "field\_%" AND meta_key LIKE "%sku%"
SELECT c.*
FROM clients c
LEFT JOIN traffic t ON t.client_id = c.id
WHERE t.arriving_date ISNULL
SELECT c.*
FROM clients c
LEFT JOIN traffic t ON t.id_client = c.id
LEFT JOIN managers m ON t.id_manager = m.id
WHERE m.name = 'Наталья'
SELECT t.id_client,
count(*)
FROM traffic t
GROUP BY id_client