home / russian-ads

russian-ads

Custom SQL query returning 6 rows

select
    target_id,
    targets.name,
    count(*) as n,
    json_object(
        "href", "/russian-ads/faceted-targets?targets=" || urllib_quote_plus(
            json_insert(:targets, '$[' || json_array_length(:targets) || ']', target_id)
        ),
        "label", json_insert(:targets, '$[' || json_array_length(:targets) || ']', target_id)
    ) as apply_this_facet,
    json_object(
        "href", "/russian-ads/display_ads?_targets_json=" || urllib_quote_plus(
            json_insert(:targets, '$[' || json_array_length(:targets) || ']', target_id)
        ),
        "label", "See " || count(*) || " ads matching " || json_insert(:targets, '$[' || json_array_length(:targets) || ']', target_id)
    ) as browse_these_ads
from ad_targets
join targets on ad_targets.target_id = targets.id
where
    json_array_length(:targets) == 0 or
    ad_id in (
        select ad_id
        from "ad_targets"
        where "ad_targets".target_id in (select value from json_each(:targets))
        group by "ad_targets".ad_id
        having count(distinct "ad_targets".target_id) = json_array_length(:targets)
    )
    and target_id not in (select value from json_each(:targets))
group by
    target_id order by n desc

Query parameters

target_idnamenapply_this_facetbrowse_these_ads
371f0 age:18 - 65+ 68 ['d5740', '75114', '371f0'] See 68 ads matching ["d5740","75114","371f0"]
4e91f location:united_states:Ferguson, St. Louis Missouri 68 ['d5740', '75114', '4e91f'] See 68 ads matching ["d5740","75114","4e91f"]
72c69 location:united_states:Baltimore Maryland 68 ['d5740', '75114', '72c69'] See 68 ads matching ["d5740","75114","72c69"]
b1201 placements:News Feed on mobile devices 68 ['d5740', '75114', 'b1201'] See 68 ads matching ["d5740","75114","b1201"]
cb431 people_who_match:People who like Black Matters 68 ['d5740', '75114', 'cb431'] See 68 ads matching ["d5740","75114","cb431"]
e6200 placements:News Feed on desktop computers 68 ['d5740', '75114', 'e6200'] See 68 ads matching ["d5740","75114","e6200"]
Powered by Datasette · Query took 19.392ms