Created
November 23, 2015 21:58
-
-
Save SputterPuttRedux/e1bde0f91a4c4c66c184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW v_dynamic_pricing_for_accounts AS | |
SELECT | |
dynamic_pricing_bid_infos.account_id, | |
dynamic_pricing_bid_infos.exclusive_lead_status, | |
dynamic_pricing_bid_infos.call_status, | |
array_agg(profiles.id) profile_ids, | |
accounts.pfp_start_date pfp_inception_date, | |
accounts.rep_user_id, | |
accounts.pfp_budget pfp_budget, | |
max_activity_prices.shared_lead_buyers | |
FROM dynamic_pricing_bid_infos | |
JOIN profiles ON dynamic_pricing_bid_infos.account_id = profiles.account_id | |
JOIN accounts ON dynamic_pricing_bid_infos.account_id = accounts.id | |
JOIN activity_prices ON dynamic_pricing_bid_infos.account_id = activity_prices.account_id | |
JOIN | |
( | |
SELECT activity_prices.account_id account_id, activity_prices.exclusive_leads_enabled shared_lead_buyers, max(activity_prices.updated_at) | |
FROM activity_prices | |
GROUP BY activity_prices.account_id, | |
activity_prices.exclusive_leads_enabled | |
) AS max_activity_prices | |
ON max_activity_prices.account_id = dynamic_pricing_bid_infos.account_id | |
-- WHERE dynamic_pricing_bid_infos.account_id = max_activity_price.account_id | |
GROUP BY | |
dynamic_pricing_bid_infos.account_id, | |
accounts.pfp_start_date, | |
accounts.rep_user_id, | |
accounts.pfp_budget, | |
dynamic_pricing_bid_infos.call_status, | |
dynamic_pricing_bid_infos.exclusive_lead_status, | |
activity_prices.account_id, | |
max_activity_prices.shared_lead_buyers | |
limit 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment