Select 行和标志列(如果找到值)
Select Rows and Flag Column if value found
我需要有关创建查询的帮助
现状:
输出 table 包含 ID 和级别。每个Id可以出现多次。
问题:
现在我想知道 1 级是否出现在 id 上,如果是,我想将其标记为数字 1。如果 Id 只有 2 级或零,则将其标记为数字 0。
输出可以取自下面的table。
使用聚合:
select id,
max(case when level = 1 then 1 else 0 end) as flag
from t
group by id;
我需要有关创建查询的帮助
现状:
输出 table 包含 ID 和级别。每个Id可以出现多次。
问题:
现在我想知道 1 级是否出现在 id 上,如果是,我想将其标记为数字 1。如果 Id 只有 2 级或零,则将其标记为数字 0。
输出可以取自下面的table。
使用聚合:
select id,
max(case when level = 1 then 1 else 0 end) as flag
from t
group by id;