mssql从2个表中选择计数

时间:2018-03-28 09:36:46

标签: sql-server

有2个表

Checklist_top
Checklist_body 

与字段IDcheckTop相关

Checklist_top
ID,Facility
1, Item1
2, Item2
3, Item3
4, Item4
5, Item5
6, Item6
7, Item1

Checklist_body
ID, IDcheckTop, Answer
1,      1,        0
2,      1,        0
3,      2,        1
4,      2,        0
5,      3,        0
6,      3,        0
7,      4,        1
8,      4,        1
9,      5,        1
10,     5,        0
11,     6,        0
12,     6,        1 
13,     7,        1
14,     7,        0 

您想编写一个计算此

中列数的查询
Facility, TOTAL, COUNT_1
Item1,      2,     1
Item2,      1,     1
Item3,      1,     0 
Item4,      1,     1
Item5,      1,     1
Item6,      1,     1
Item7,      1,     1

1 个答案:

答案 0 :(得分:0)

尝试以下查询

index/_search?q=name.my_standard:jdxi