home / russian-ads

russian-ads

Custom SQL query returning 15 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
17183 interests:Black nationalism 4 ['1073c', '9e07c', '17183'] See 4 ads matching ["1073c","9e07c","17183"]
313af interests:African-American Civil Rights Movement (1954—68) 4 ['1073c', '9e07c', '313af'] See 4 ads matching ["1073c","9e07c","313af"]
59d75 language:English (US) 4 ['1073c', '9e07c', '59d75'] See 4 ads matching ["1073c","9e07c","59d75"]
5e075 language:English (UK) 4 ['1073c', '9e07c', '5e075'] See 4 ads matching ["1073c","9e07c","5e075"]
aabe0 interests:Black Consciousness Movement 4 ['1073c', '9e07c', 'aabe0'] See 4 ads matching ["1073c","9e07c","aabe0"]
b1201 placements:News Feed on mobile devices 4 ['1073c', '9e07c', 'b1201'] See 4 ads matching ["1073c","9e07c","b1201"]
e6200 placements:News Feed on desktop computers 4 ['1073c', '9e07c', 'e6200'] See 4 ads matching ["1073c","9e07c","e6200"]
ebe26 interests:African-American history 4 ['1073c', '9e07c', 'ebe26'] See 4 ads matching ["1073c","9e07c","ebe26"]
ec3ac location:United States 4 ['1073c', '9e07c', 'ec3ac'] See 4 ads matching ["1073c","9e07c","ec3ac"]
4801f age:16 - 65+ 3 ['1073c', '9e07c', '4801f'] See 3 ads matching ["1073c","9e07c","4801f"]
afc04 interests:Pan—Africanism 3 ['1073c', '9e07c', 'afc04'] See 3 ads matching ["1073c","9e07c","afc04"]
c4200 interests:African—American culture 3 ['1073c', '9e07c', 'c4200'] See 3 ads matching ["1073c","9e07c","c4200"]
96bbd interests:Pan-Africanism 1 ['1073c', '9e07c', '96bbd'] See 1 ads matching ["1073c","9e07c","96bbd"]
c3b9b age:16 — 65+ 1 ['1073c', '9e07c', 'c3b9b'] See 1 ads matching ["1073c","9e07c","c3b9b"]
d4179 interests:African-American culture 1 ['1073c', '9e07c', 'd4179'] See 1 ads matching ["1073c","9e07c","d4179"]
Powered by Datasette · Query took 23.737ms