79-81-103
select avg(proceeds_set)from sales_check_position as salleft join spr_product as prod on sal.id_product = prod.id_productleft join spr_product_groups spg on prod.group_id = spg.group_idwhere spg.group_id IN ('УТ-00020014', '00000000024', 'УТ-00008993', 'УТ-00020015', '00000000058', 'УТ-00008994', '00000000114', 'УТ-00008995', 'УТ-00020016', 'УТ-00010837');
WITH recent_purchases AS ( SELECT DISTINCT sc.push_id FROM spr_check sck JOIN spr_client sc ON sck.card_number = sc.card_number JOIN spr_store ss ON sck.id_store = ss.id_store WHERE sck.order_date >= CURRENT_DATE - INTERVAL '1 month' AND ss.city = 'Кемерово'),excluded_users AS ( SELECT DISTINCT sc.push_id FROM spr_check sck JOIN sales_check_position scp ON sck.id_check = scp.id_check JOIN spr_product sp ON scp.id_product = sp.id_product JOIN spr_client sc ON sck.card_number = sc.card_number WHERE sp.group_id IN ( 'УТ-00020014', '00000000024', 'УТ-00008993', 'УТ-00020015', '00000000058', 'УТ-00008994', '00000000114', 'УТ-00008995', 'УТ-00020016', 'УТ-00010837' ))SELECT DISTINCT rp.push_id, sc.firstnameFROM recent_purchases rpJOIN spr_client sc ON rp.push_id = sc.push_idLEFT JOIN excluded_users eu ON rp.push_id = eu.push_idWHERE eu.push_id IS NULLORDER BY rp.push_id;
WITH recent_purchases AS (
SELECT DISTINCT
sc.push_id
FROM
spr_check sck
JOIN
spr_client sc ON sck.card_number = sc.card_number
JOIN
spr_store ss ON sck.id_store = ss.id_store
WHERE
sck.order_date >= CURRENT_DATE - INTERVAL '1 month'
AND ss.city = 'Кемерово'
),
excluded_users AS (
SELECT DISTINCT
sc.push_id
FROM
spr_check sck
JOIN
sales_check_position scp ON sck.id_check = scp.id_check
JOIN
spr_product sp ON scp.id_product = sp.id_product
JOIN
spr_client sc ON sck.card_number = sc.card_number
WHERE
sp.group_id IN (
'УТ-00020014', '00000000024', 'УТ-00008993', 'УТ-00020015', '00000000058', 'УТ-00008994', '00000000114', 'УТ-00008995', 'УТ-00020016', 'УТ-00010837'
)
)
SELECT DISTINCT
rp.push_id,
sc.firstname
FROM
recent_purchases rp
JOIN
spr_client sc ON rp.push_id = sc.push_id
LEFT JOIN
excluded_users eu ON rp.push_id = eu.push_id
WHERE
eu.push_id IS NULL
ORDER BY
rp.push_id;