我的表设置类似于以下内容:
Userid | LastFirstMI | Active
1 Doe, Jane S False <<<
2 Doe, Jane S True
3 Smith, John P False
4 Lee, Bob R False
5 Bob, Joe L False <<<
6 Bob, Joe L True
我只想选择Active值为False的重复名称。我用&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;我搜索过并找到了类似的问题,但我似乎无法找到一个显示如何选择特定副本的问题。提前谢谢。
答案 0 :(得分:0)
select t1.userid, t1.LastFirstMI, t1.Active from table t1,table t2
where t1.active='False' and t1.LastFirstMI=t2.LastFirstMI and t2.active='True'
尝试上面的代码,如果需要,请根据您的数据库引擎更改active=False
条件。
答案 1 :(得分:0)
假设您的列活动为字符串
这应该适用于mysql和SQLServer
select * from my_table where
Active = 'False' and LastFirstMi in (
select t.LastFirstMi from (
select LastFirstMI, count(*)
from my_table
group LastFirstMI
having count(*)>1
) t
)
答案 2 :(得分:0)
您可以在大多数数据库中使用row_number:
Select *
From (
Select t.*
,row_number() over (partition by lastfirstMI order by Active) rn
From your_table t
) t where rn = 1
答案 3 :(得分:0)
如果有相应的Active = 'False'
帐户,这将返回Active = 'True'
的重复项。
select userid, LastFirstMI, Active
from t
where t.Active = 'False'
and exists (
select 1
from t as i
where i.LastFirstMi = t.LastFirstMi
and i.Active = 'True'
)
即使没有相应的Active = 'False'
帐户,也会返回Active = 'True'
的所有重复项。
select userid, LastFirstMI, Active
from t
where t.Active = 'False'
and exists (
select 1
from t as i
where i.LastFirstMi = t.LastFirstMi
and i.UserId <> t.UserId
)
答案 4 :(得分:0)
<select v-model="selected.car" :change="getModels()">
<option v-for="car in cars" value="car.id">{{ car.name }}</option>
</select>
<select v-model="selected.model" :change="getYear()">
<option v-for="model in models" :value="model.id">{{ model.name }}</option>
</select>
...