


DROP VIEW IF EXISTS account_insights_by_gender CASCADE;

CREATE VIEW account_insights_by_gender AS
SELECT 
    time, 
    account_id, 
    gender, 
    SUM(impressions) AS impressions, 
    SUM(clicks) AS clicks,
    SUM(spend) AS spend, 
    SUM(link_click) AS link_click, 
    SUM(landing_page_view) AS landing_page_view,
    SUM(lead) AS lead
FROM campaign_insights_by_gender
GROUP BY time, account_id, gender;


DROP VIEW IF EXISTS account_insights_by_age CASCADE;

CREATE VIEW account_insights_by_age AS
SELECT 
    time, 
    account_id, 
    age, 
    SUM(impressions) AS impressions, 
    SUM(clicks) AS clicks,
    SUM(spend) AS spend, 
    SUM(link_click) AS link_click, 
    SUM(landing_page_view) AS landing_page_view,
    SUM(lead) AS lead
FROM campaign_insights_by_age
GROUP BY time, account_id, age;

DROP VIEW IF EXISTS account_insights_by_gender_and_age CASCADE;

CREATE VIEW account_insights_by_gender_and_age AS
SELECT 
    time, 
    account_id,
    gender, 
    age, 
    SUM(impressions) AS impressions, 
    SUM(clicks) AS clicks,
    SUM(spend) AS spend, 
    SUM(link_click) AS link_click, 
    SUM(landing_page_view) AS landing_page_view,
    SUM(lead) AS lead
FROM campaign_insights_by_gender_and_age
GROUP BY time, account_id, age, gender;

