gpt4 book ai didi

sql - 获取具有列组合的记录

转载 作者:行者123 更新时间:2023-12-02 20:05:07 25 4
gpt4 key购买 nike

这是我的示例表

CREATE TABLE agentskills 
(
id INT PRIMARY KEY NOT NULL IDENTITY,
skilluserid INT,
skillid INT NOT NULL,
skilltypeid INT,
priority INT DEFAULT 0
)

这些是我的示例数据

INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (1,21,1,1)
INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (1,22,1,1)

INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (2,23,1,1)
INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (2,24,1,1)

INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (3,21,1,1)
INSERT INTO AGENTSKILLS (skilluserid , skillid, SKILLTYPEID,priority ) VALUES (3,22,1,1)

这里,'skilluserid'是具有技能'skillid'的用户的ID

如何获取具有 Skillid 组合的用户/skilluserid?

例如:获取技能 ID 为 21 和 22 或 22 和 21 或 21,22,23 的用户。具有 21 和 22 的任意组合。

最佳答案

您可以使用聚合和having:

select skilluserid
from agentskills
where skillid in (21, 22)
group by skilluserid
having count(distinct skillid) = 2; -- "2" = size of list in where clause

关于sql - 获取具有列组合的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55591118/

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