[英]How to SELECT rows that has same values in column 1 but different values in column 2?
I have this query below: 我在下面有这个查询:
I've managed to filter out the names with the SAME YEAR but DIFFERENT TID, then how to I pick these names out without duplication? 我设法用相同的年份但不同的TID过滤掉了名字,那么如何挑选出没有重复的名字呢?
OUTPUT: OK the desire output should be like this per request. 输出:可以,每个请求的期望输出应该是这样的。
firstname | lastname | year | tid
Alex Hannum 1956 MI1
Alex Hannum 1956 ROC
Alex Hannum 1956 STL
Alex Hannum 1956 SYR
Alvin Attles 1969 PH1
Alvin Attles 1969 SFW
Alvin Attles 1970 PH1
Alvin Attles 1970 SFW
Andrew Levane 1952 MI1
Andrew Levane 1952 ROC
Andrew Levane 1952 SYR
.... and so on. .... 等等。
I think you are looking for the players who opt-out two or more tid in a year, 我想您是在寻找一年内选择退出两个或两个以上比赛的球员,
If so you can use the below query on the data you displayed in screen-shot assuming it also has one more column which identify players uniquely. 如果是这样,您可以对屏幕快照中显示的数据使用以下查询,前提是该数据还有另外一列唯一标识玩家。
SELECT firstname
, lastname
, year
, tid
FROM player
where player_id
in (select distinct player_id
from player
group by firstname
, lastname
, year
having count(*) >1) SELECT firstname
, lastname
, year
, tid
FROM player
,其中player_id
在(选择不同player_id
从player
组由firstname
, lastname
, year
具有COUNT(*)> 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.