我必须得到以下输出 [英] I have to get the below output
本文介绍了我必须得到以下输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表:
Id。类型
1. Xxx
1. Bbb
2. Xxx
3. Xxx
4. Yyy
4. Xxx
输出:
Id。类型
2. Xxx
3. Xxx
我尝试过:
输出应该显示包含xxx的类型,只有一个id
Table :
Id. Type
1. Xxx
1. Bbb
2. Xxx
3. Xxx
4. Yyy
4. Xxx
Output:
Id. Type
2. Xxx
3. Xxx
What I have tried:
Output should display the type containing xxx which having only one entry of id
推荐答案
你需要的条目GROUP BY带有HAVING子句来标识单个条目行:
You need GROUP BY with a HAVING clause to identify the single entry rows:
SELECT ID FROM MyTable GROUP BY ID HAVING COUNT(ID) = 1
这只会为您提供您感兴趣的ID值:
That gives you just the ID values you are interested in:
ID
2
3
然后使用JOIN返回原始表格以获取类型和ID:
You then use a JOIN back to the original table to get the Type and ID together:
SELECT a.ID, b.Type
FROM (SELECT ID FROM MyTable GROUP BY ID HAVING COUNT(ID) = 1 ) a
JOIN MyTable b ON a.ID = b.ID
它可以为您提供所需的结果:
Which gives you the result you want:
ID Type
2 xxx
3 xxx
这篇关于我必须得到以下输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文