Prøv dette:
SELECT
--A bunch of columns from several tables
FROM prd_acct_cmp_grp pacg
JOIN product_acct pa
ON pacg.product_account_id = pa.product_account_id
JOIN customer_acct ca
ON pa.customer_acct_id = ca.customer_acct_id
JOIN prd_acct_acct_cmp pac
ON pacg.product_account_id = pac.product_account_id
AND pacg.occurencce_number = pac.occurence_number
AND pac.prcmp_code = 'USAGE'
LEFT JOIN (SELECT DISTINCT member_id, group_id
FROM group_members
WHERE group_id IN (33158, 27156, 35376, 36217)) gm
ON ca.customer_acct_id = gm.member_id
LEFT JOIN sales_hierarchy sh
ON ca.primary_sales_rep = sh.sales_rep_id
LEFT JOIN sales_region sr
ON sh.region_cd = sr.sales_region_code
LEFT JOIN pacg_usage pu
ON pacg.component_group_cd = pu.component_group_cd
AND pacg.component_grp_val = pu.component_grp_val
WHERE pacg.component_group_cd = 'AN'
AND pacg.component_grp_val IN (%s) --string that is added in later