gpt4 book ai didi

mysql - 如何排除有重复的行? (消除)

转载 作者:行者123 更新时间:2023-11-29 16:29:40 26 4
gpt4 key购买 nike

有人可以帮助我执行一个查询,其中查询的重复元素被删除

Select * from table where APPNAME = 'Ap1' or APPNAME= 'Ap2'

使用 DISTINCT 的结果

id | APPNAME| USERNAME|
1 Ap1 User1
2 Ap2 User1
3 Ap1 User3
4 Ap2 User4
5 Ap1 User5
6 Ap1 User6
7 Ap2 User6

在此表中,用户 1 和 6 都有两个应用程序。必须从查询中删除这两个用户。

预期结果是

id | APPNAME| USERNAME|    
1 Ap1 User3
2 Ap2 User4
3 Ap1 User5
<小时/>

如果我使用 DISTINCT 那么它会消除重复项,我需要将它们都消除。

使用 DISTINCT 的结果

id | APPNAME| USERNAME|
1 Ap1 User1
2 Ap1 User3
3 Ap2 User4
4 Ap1 User5
5 Ap2 User6

谢谢

最佳答案

select distinct * from table where APPNAME = 'Ap1' or APPNAME= 'Ap2' group by APPNAME having (count(APPNAME)=1);

关于mysql - 如何排除有重复的行? (消除),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com