Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在1:n关系中查找重复项_Sql_Ms Access_Duplicates - Fatal编程技术网

Sql 在1:n关系中查找重复项

Sql 在1:n关系中查找重复项,sql,ms-access,duplicates,Sql,Ms Access,Duplicates,可能是个新手问题,但我完全没有回答:我有一个处方数据库,其中有两个表: **prescriptions**, with amongst others a field ID (primary key) **lines**, amongst others with fields ID_P (foreign key) and name (my target values) 这两个表以1(处方):n(行)关系链接 我需要知道,在这种组合中,是否已经在这些表中输入了一组给定的名称,但顺序可能不同 简短

可能是个新手问题,但我完全没有回答:我有一个处方数据库,其中有两个表:

**prescriptions**, with amongst others a field ID (primary key)

**lines**, amongst others with fields ID_P (foreign key) and name (my target values)
这两个表以1(处方):n(行)关系链接

我需要知道,在这种组合中,是否已经在这些表中输入了一组给定的名称,但顺序可能不同

简短示例:给定一个带有行a、B、C的处方,是否已经输入了一个带有行a、B、C、订单B、a、C或这些行的任何排列的处方

我的想法最终是在表格处方中插入一个搜索字段,其中包含属于该处方的表格“行”的所有字段“名称”的内容,但这似乎并不理想

你知道如何达到这个目标吗

示例:表格行:

+----+------+----------------------+
| ID | ID_P |          name        | 
+----+------+----------------------+
| 1  | 1    |Metronidazol          |
| 2  | 1    |Erythromycin          |
| 3  | 1    |Basiscreme            |
| 4  | 2    |Metronidazol          |
| 5  | 2    |Vaseline              |
| 6  | 3    |Erythromycin          |
| 7  | 3    |Clotrimazol           |
| 8  | 3    |Basiscreme            |
| 9  | 4    |Clotrimazol           |
| 10 | 4    |Basiscreme            | 
+----+------+----------------------+

输入Basiscreme+甲硝唑+红霉素的名称应以成功告终,而甲硝唑+Basiscreme则不然。或者:克霉唑+碱性克伦是成功的,红霉素+碱性克伦不是。

您可以按名称分组并返回计数>=3的

select
    name, count(*)
from
    lines
where
    name in ('Basiscreme', 'Metronidazol', 'Erythromycin')
group by 
    name
having 
    count(*) >= 3;
名称|(无列名) :--------- | ---------------: 基本原则| 3
DBFIDLE

样本:表中的“线”包括“1”、“红霉素”、“1”、碱式氯化铵、“2”、“甲硝唑”、“2”凡士林、“3”、克霉唑、“3”甲硝唑、“3”碱式氯化铵。输入名称“Basiscreme”、“Metronidazol”、“Clotrimazol”应以“Metronidazol”+“Basiscreme”结尾。使用并编辑您的问题以提供样本数据和预期结果。请从样本数据中显示所需结果的表输出。不清楚你输入的名字是什么意思。 name | (No column name) :--------- | ---------------: Basiscreme | 3