I'm trying to filter a derived table when a field has been filtered. This is one of multiple views that are used to build a dashboard.
The following is outputting sql that looks like this:
WHERE (group.name = 'LYON')
When I want something that looks like:
WHERE (g.name = 'LYON')
I know I could probably use parameters, but there are multiple views and joins brining this thing together and a shared parameter feels much harder to manage.
view: listing_accuracy {
derived_table: {
sql:
SELECT
src.account_id as account_id,
COUNTIF(l.match_quality = 'good' OR l.is_verified) AS accurate,
COUNTIF(l.match_quality != 'good' AND NOT l.is_verified) AS inaccurate,
COUNTIF(l.listing_id IS NULL) AS missing
FROM
`@{project}.@{partition_id}.Listing` AS l
RIGHT JOIN
`@{project}.@{partition_id}.AccountSource` AS src ON l.account_id = src.account_id AND l.source_id = src.source_id
JOIN
`@{project}.@{partition_id}.Source` AS s ON src.source_id = s.source_id
WHERE
s.enabled IS TRUE AND s.deleted IS NULL
{% if group.name._is_filtered %}
AND src.source_id IN (
SELECT gs.source_id
FROM
`@{project}.@{partition_id}.Group` as g
LEFT OUTER JOIN
`@{project}.@{partition_id}.GroupSource` as gs on g.group_id = gs.group_id
WHERE {% condition group.name %} ${group.name} {% endcondition %}
)
{% else %}
AND 1=1
{% endif %}
GROUP BY
src.account_id ;;
}
Solved! Go to Solution.
Well...I don't know why this works but it does.
{% condition group.name %} g.name {% endcondition %}
Well...I don't know why this works but it does.
{% condition group.name %} g.name {% endcondition %}
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |