所以我确实有选择女巫看起来像这样:
SELECT * FROM database1 WHERE ID = 3933185
女巫选择返回给我的记录是:
ID VALUE ATTR_VALUE
3,933,185 1 1
3,933,185 1 1
3,933,185 1 1
3,933,185 1 2
3,933,185 1 2
正如您所看到的,每attr_value
列可能有不同的值,1
或者2
仅此而已。
那么我应该添加什么来进行检查,当attr_value
存在 value 时1
,它将返回记录 where attr_value = 1
,在其他情况下它将返回 where attr_value = 2
。
希望我的问题很清楚。
我想你想要:
select t.*
from t
where t.value = (select min(t2.value) from t t2 where t2.id = t.id);
您还可以使用分析函数:
select t.*
from (select t.*, min(t.value) over (partition by id) as min_value
from t
) t
where value = min_value;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句