Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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
schemaId other-sql 2008中存在计数引用ID_Sql_Sql Server 2008 - Fatal编程技术网

schemaId other-sql 2008中存在计数引用ID

schemaId other-sql 2008中存在计数引用ID,sql,sql-server-2008,Sql,Sql Server 2008,我有两张桌子 表1: ReferenceId |Name 00000001 | Terminal A 00000222 | Terminal 1 00000223 | Terminal 11 00000023 | Terminal 2 00000030 | Terminal B 00000031 | Terminal B1 00000032 | Terminal B2 0000003

我有两张桌子

表1:

 ReferenceId    |Name
    00000001    | Terminal A
    00000222    | Terminal 1
    00000223    | Terminal 11
    00000023    | Terminal 2
    00000030    | Terminal B
    00000031    | Terminal B1
    00000032    | Terminal B2
    00000033    | Terminal 4
    00000034    | Terminal D
    00000035    | Terminal E
    00000036    | Terminal F
    00000037    | Terminal B3
表2:

 SchemaId   | ReferenceId 
    1           | 00000001-00000023,00000222,00000035-00000036
    2           | 00000007-00000023,00000223,00000036-00000037
    3           | 00000001-00000030,00000222-00000223
    4           | 00000001-99999999
例如: Schmema1(Count ReferenceId存在于表1和SchemaId Other中)

示例:Schmema2

 ReferenceId | Schmema      | Isdisplay     | Note
    00000007    |0          | 0             | Not exists in table1
    ...
    00000023    |1,3,4      | 1         
    00000223    |3,4        | 1
    00000036    |1,4        | 1         
    00000037    |4          | 1     
    => **total** 4
示例:Schmema3

ReferenceId | Schmema   | Isdisplay     | Note
00000001    |1,4        | 1     
00000023    |1,2,4      | 1
00000030    |4          | 1         
00000222    |1,4        | 1         
00000223    |2,4        | 1
=> **total** 5
示例:Schmema4

 ReferenceId | Schmema      | Isdisplay     | Note
    00000001    |1,3        | 1     
    00000002    |0          | 0
    00000003    |0          | 0
    ...
    00000023    |1,2,3      | 1
    00000024    |0          | 0
    ...
    00000030    |3          | 1
    00000031    |0          | 0         | Not exists in schmemaId other
    00000032    |0          | 0         | Not exists in schmemaId other
    ...
    00000035    |1          | 1         
    00000036    |1,2        | 1
    00000037    |2          | 1         
    ...
    00000222    |1,3        | 1         
    00000223    |2,3        | 1
    => **total** 8
我期望得到的结果是:

SchemaId    | ReferenceId           |CountReferenceIdExistsSchemaIdOther
1           | 00000001-00000023,00000222,00000035-00000036      |5
2           | 00000007-00000023,00000223,00000036-00000037      |4
3           | 00000001-00000023,00000222-00000223               |5
4           | 00000001-99999999                                 |8

如何获得预期的结果?请你帮帮我。

你有什么问题?&到目前为止,您尝试了什么?在参考ID 00000001的模式1中,为什么只考虑模式3和4?为什么不考虑模式1?架构2中的ReferenceID 0000000 7也是如此。
SchemaId    | ReferenceId           |CountReferenceIdExistsSchemaIdOther
1           | 00000001-00000023,00000222,00000035-00000036      |5
2           | 00000007-00000023,00000223,00000036-00000037      |4
3           | 00000001-00000023,00000222-00000223               |5
4           | 00000001-99999999                                 |8