gpt4 book ai didi

mysql - 如何获取mysql表中某一列中只有单个条目的数据?

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

I have a table named as scholar and it has a column studentid now i want to fetch the data where studentid comes only once, one id can have multiple entry in the studentid column

下面是我的结构数据

enter image description here

现在我想获取studentid = 123和154的所有数据,因为这些数据只出现一次

如下是我想要的输出:

![enter image description here

那么查询是什么,请帮忙

最佳答案

我认为您想要这样的查询:

SELECT *,count(*) as cnt FROM scholar GROUP BY studentid HAVING cnt = 1

但这并不是最快的解决方案。

或者你可以使用这个:

SELECT * FROM scholar GROUP BY studentid HAVING count(id) = 1

关于mysql - 如何获取mysql表中某一列中只有单个条目的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41590307/

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