简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM