选择只有一种类型的组的列(mysql)

时间:2016-10-11 11:05:01

标签: mysql

我正在使用Mysql。

我有两个表格,其中包含有关Excel表格的信息。

第一个表包含文档信息,例如 sheetID createdBy dateOfCreation

第二个表包含每个Excel工作表的详细信息: sheetID colName colType

工作表可以包含多个 colName

colType 可以是A,B或C.

sheetID 通过外键相互链接。

示例

表1:

1   ABC.XLS    GAURAV
2   XYZ.XLS    FOOBAR
3   QWE.XLS    FOO
4   QZXC.XLS   BAR

表2:

1   name    A
1   place   A
1   amount  B
1   link    C
2   name    A
2   website C
3   name    A
4   home    A
4   name    A
4   fname   A

我需要编写一个返回所有那些只有一种数据类型的工作表的查询。

在此示例中, sheetId 4只有“A”类型的数据。

编辑1: scaisEdge提供的解决方案有效。

可以扩展此查询以查找包含所有3种类型列的工作表。与上面的例子中一样, sheetId 1具有所有三种类型。

1 个答案:

答案 0 :(得分:0)

您可以使用非转发

 select t1.* 
 from table_1 t1
 inner join table_2 t2 on t1.sheetDI = t2.sheetID
 where t2.sheetID not in (select distinct sheetID from table_2 
                           where coltype <>'A')
 and t2.colType = 'A' 
相关问题