如果您想要对字段进行计数,并且如果count distinct字段= 1,则可以使用该列,但如果count distinct字段>1,则将其设置为"not identifiable“。
表如下所示
store furniture furniture_model
A ikea round
A ikea square
B ikea round
C ikea square结果
A ikea no model wrong data
B ikea round
C ikea square使用
SELECT ID, furniture,
CASE
WHEN COUNT(DISTINCT furniture_model) > 1 THEN 'Non Identified Old Model'
ELSE furniture_model
END old_model
FROM Table发布于 2020-03-01 03:49:01
我只会使用:
select store, table,
(case when min(table_model) = max(table_model) then min(table_model)
else 'Non Identified Old Model'
end)
from t
group by store, table;请注意,对于列名来说,table是一个非常糟糕的名称。即使它被允许,它也是一个SQL关键字。更糟糕的是,它意味着数据库世界中的某些东西--而不是“列”。
https://stackoverflow.com/questions/60469011
复制相似问题