gpt4 book ai didi

php - 如何从表中获取唯一的数据?

转载 作者:行者123 更新时间:2023-11-29 13:11:04 25 4
gpt4 key购买 nike

我在mysql中有一个表,其中有bus_id和cus_id。我想从表中获取 B108 作为返回值,因为我想要的结果的值不等于 C108,并且 C108 也有 B109。所以我也不想要第 3 行的值。我只想得到第 2 行作为结果。请建议我对这些表进行选择查询。

我的 table 是:

enter image description here

最佳答案

您可以单独使用组表并检测每列的重复值,然后使用这些值过滤表。

    select * from table 
where cus_id not in
(select cus_id from table
group by cus_id
having count(*) > 1)
and
bus_id not in
(select bus_id from table
group by bus_id
having count(*) > 1)

关于php - 如何从表中获取唯一的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22089422/

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