我有一个父母/子女/子女/子女类型表关系,定义如下:
tableA: parentID description
tableB: childID parentId description
tableC: grandchildID childId description itemComplete
I need to write a query that will list all records in tableB for any given parentID, along with the total count of grandchild records and the total count of grandchild records completed (where itemComplete = true).
父母 ID将成为条款的一部分(摘自括号内为Id=x的表B)。 我可以列举的问题是,如何从表格中得出计数。 C 因为这一计算取决于儿童生长的目前价值。
换言之,我需要某种怀疑:
select description,
(select count (*) from tableC where childId = X) as Items,
(select count (*) from tableC where childId = X And itemComplete = true) as CompleteItems
from tableB where parentId=Y
如果X是表B中现有的儿童。 我如何在我的分询问中逐个提及儿童,以便完成项目数目和项目数目?