我有一张表格,里面有名字和技术字段。
-----------------------------
|name | technologies |
-----------------------------
|shashin | reactjs |
-----------------------------
|shashin | mysql |
-----------------------------
|krupali | express |
-----------------------------
|paras | mysql |
-----------------------------
|shashin | express |
-----------------------------
|paras | php |
-----------------------------
|krupali | php |
-----------------------------
|shashin | php |
-----------------------------我想找到至少在所有这些技术中工作过的人的名字,mysql,express。
输出:
-------------
|name |
-------------
|shashin |
-------------发布于 2019-02-09 06:53:13
你可以试着像下面这样做。
select name from TableName
group by name
having count(distinct technologies) > 2如果您想要使用特定的技术,可以尝试如下所示。
select name from TableName
where technologies in('reactjs', 'mysql', 'express')
group by name
having count(distinct technologies) > 2发布于 2019-07-04 13:58:31
接受的答案很好,但我更喜欢
SELECT name
FROM table_name
WHERE technologies IN ('reactjs', 'mysql', 'express')
GROUP BY name
HAVING COUNT(DISTINCT technologies) = 3DISTINCT确保每个名称都有确切的3条记录,前提是它们匹配所有三种技术。任何其他技术都将被WHERE删除。
实际上,如果将唯一的复合索引放在原始表上的(name, technology)上,并且只允许每种技术为给定名称出现一次,则可以从上面的查询中删除DISTINCT technologies。
SELECT name
FROM table_name
WHERE technologies IN ('reactjs', 'mysql', 'express')
GROUP BY name
HAVING COUNT(*) = 3作为附带说明,我很想将我的人员和技术分离到不同的表中,并将它们与第三个表连接在一起
id,name,…id,name,…id,person_id,technology_id将person_id和technology_id作为相应表的外键,并在
name(person_id, technology_id)那么您的查询就会变成
SELECT p.id,
p.name AS person,
t.name AS technology
FROM person p
JOIN person_technology pt
ON pt.person_id = p.id
JOIN technology t
ON t.id = pt.technology_id
AND t.name IN ('reactjs', 'mysql', 'express')
GROUP BY p.id, p.name
HAVING COUNT(*) = 3https://stackoverflow.com/questions/54603906
复制相似问题