gpt4 book ai didi

SQL 选择所有不同值存在于另一列中的位置

转载 作者:行者123 更新时间:2023-12-02 08:45:33 28 4
gpt4 key购买 nike

我有一个表格,其中前两行是公司、年份。每个公司都会有一些年份,但不一定都是:

ABC | 2010
ABC | 2011
ABC | 2012
BBC | 2011 //does not have all the years, don't want to select it

我想选择一个包含所有年份(不仅仅是其中一些)的公司列表,但我在编写一个选择查询来执行此操作时遇到了问题。我想这真的很容易,但出于某种原因我想不通。

最佳答案

尝试

select company
from your_table
group by company
having count(distinct year) = (select count(distinct year) from your_table)

关于SQL 选择所有不同值存在于另一列中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12750446/

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