home / russian-ads

russian-ads

Custom SQL query returning 10 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
313af interests:African-American Civil Rights Movement (1954—68) 2 ['1073c', 'a340a', '313af'] See 2 ads matching ["1073c","a340a","313af"]
371f0 age:18 - 65+ 2 ['1073c', 'a340a', '371f0'] See 2 ads matching ["1073c","a340a","371f0"]
4accc placements:on pages: News Feed on desktop computers 2 ['1073c', 'a340a', '4accc'] See 2 ads matching ["1073c","a340a","4accc"]
8e7b3 interests:Jr. 2 ['1073c', 'a340a', '8e7b3'] See 2 ads matching ["1073c","a340a","8e7b3"]
a0f55 interests:Malcolm X 2 ['1073c', 'a340a', 'a0f55'] See 2 ads matching ["1073c","a340a","a0f55"]
b1201 placements:News Feed on mobile devices 2 ['1073c', 'a340a', 'b1201'] See 2 ads matching ["1073c","a340a","b1201"]
cc5ed location_living_in:United States 2 ['1073c', 'a340a', 'cc5ed'] See 2 ads matching ["1073c","a340a","cc5ed"]
d003e placements:Instream Video on mobile devices 2 ['1073c', 'a340a', 'd003e'] See 2 ads matching ["1073c","a340a","d003e"]
d6ade interests:Martin Luther King 2 ['1073c', 'a340a', 'd6ade'] See 2 ads matching ["1073c","a340a","d6ade"]
ebe26 interests:African-American history 2 ['1073c', 'a340a', 'ebe26'] See 2 ads matching ["1073c","a340a","ebe26"]
Powered by Datasette · Query took 28.204ms