0

我在我的视图中将 CASE 语句添加到我的过滤器中。我基本上希望如果用户键入Harry过滤应该发生在Gryffindor. 这是我的代码:

filter: house {
    # type: string
    # sql: ${TABLE}.house ;;
    sql:  CASE
            WHEN ${TABLE}.house LIKE '%harry%' THEN ${TABLE}.house = 'gryffindor'
            WHEN ${TABLE}.house LIKE '%luna%' THEN ${TABLE}.house = 'ravenclaw'
            WHEN ${TABLE}.house LIKE '%ernie%' THEN ${TABLE}.house = 'hufflepuff'
            WHEN ${TABLE}.house LIKE '%draco%' THEN ${TABLE}.house = 'slytherin'
          ELSE ${TABLE}.house = ${TABLE}.house END ;;
  }

当我去探索并harry在我的过滤器中输入时,它会返回所有值,例如:

gryffindor
ravenclaw
hufflepuff
slytherin
other

这是我的 SQL 代码的样子:

SELECT
    "house" AS "hogwarts.house"
FROM
    "schools"."hogwarts" AS "hogwarts"
WHERE (CASE
            WHEN hogwarts.house LIKE '%harry%' THEN hogwarts.house = 'gryffindor'
            WHEN hogwarts.house LIKE '%luna%' THEN hogwarts.house = 'ravenclaw'
            WHEN hogwarts.house LIKE '%ernie%' THEN hogwarts.house = 'hufflepuff'
            WHEN hogwarts.house LIKE '%draco%' THEN hogwarts.house = 'slytherin'
            ELSE hogwarts.house = hogwarts.house END )
GROUP BY
    1
ORDER BY
    1
LIMIT 500

这个查询显然会返回所有的值。

有没有办法在过滤器中输入harry它只返回:

gryffindor
4

0 回答 0