简体   繁体   English

从 SQL 服务器中的预定比赛中获取唯一记录

[英]Get the unique records from scheduled matches in SQL Server

I have a table like:我有一张像这样的桌子:

Team1团队1 Team2团队2
CSK CSK SRH性生殖健康
SRH性生殖健康 CSK CSK
MI心肌梗死 RR RR
RR RR MI心肌梗死
DC直流 MI心肌梗死

I want to get unique records like below using MSSQL server:我想使用 MSSQL 服务器获得如下的唯一记录:

Team1团队1 Team2团队2
CSK CSK SRH性生殖健康
RR RR MI心肌梗死
DC直流 MI心肌梗死

If the order is not important you can simply arrange the two teams alphabetically and then do a SELECT DISTINCT .如果顺序不重要,您可以简单地按字母顺序排列两个团队,然后执行SELECT DISTINCT Like this:像这样:

SELECT DISTINCT
CASE WHEN team1 < team2 THEN team1 ELSE team2 END AS team1,
CASE WHEN team1 < team2 THEN team2 ELSE team1 END AS team2
FROM teams;

As it's Monday morning and you are a newbie, I am being kind to you.因为是星期一早上,你是新手,我对你很好。 Please note for future reference, however, when posting a question here, you are expected to show more effort yourself.请注意以供将来参考,但是,在此处发布问题时,您应该自己表现出更多的努力。

When asking a question involving SQL, it helps enormously to include in your question CREATE statements for the tables involved together with INSERT statements to enter your sample data.当问一个涉及 SQL 的问题时,在您的问题中包含对涉及的表的CREATE语句以及INSERT语句以输入您的示例数据非常有帮助。

And then always show what you have attempted yourself, no matter how embarassing.然后总是展示你自己尝试过的东西,无论多么尴尬。 Everyone makes mistakes at first.每个人一开始都会犯错。 Some of us 30 years later are still making mistakes. 30年后,我们中的一些人仍在犯错误。 The best way to learn is to get help fixing your mistakes, but if we cannot see, what you have tried, it makes it harder to know at what level to pitch the answer.最好的学习方法是寻求帮助来纠正你的错误,但如果我们看不到你尝试了什么,就很难知道在什么水平上提出答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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