1

How can I filter a nested repeating record when using an aggregation function and WITHIN clause?

For example: I have a scheme where each record represents a person and each person has a nested childrens record. For each child I have name and age.

I can easily count the children for each person by using COUNT(children.name) WITHIN RECORD, but what if I want to count only the children with age>18?

4

1 回答 1

1

Try something along these lines:

SELECT SUM(cnt) FROM
  (SELECT MAX(IF(children.name > 18, 1, 0) WITHIN RECORD AS cnt FROM table1)
于 2013-04-01T21:22:14.240 回答