我想知道x次怀孕的次数.
name | baby_dob1 | baby_dob2 | baby_dob3 | Pregnant |
---|---|---|---|---|
Mary | 20-01-2021 | 02-03-2022 | True | |
Esther | 10-01-2020 | True | ||
Helen | 01-01-2020 | 02-02-2021 | 09-09-2023 | False |
Laura | True | |||
Queen | 25-04-2020 | 22-04-2022 | 18-07-2022 | False |
输出应如下所示:
Category of pregnancies | Number of women |
---|---|
3 | 3 |
2 | 1 |
1 | 1 |
Meaning:
3 women have been pregnant three times.
1 woman has had two pregnancies.
1 woman has had one pregnancy.
逻辑:
在系统中你只能怀孕三次.
baby_dob1
is the date of birth of the first baby.
baby_dob2
is the date of birth of the second baby.
baby_dob3
is the date of birth of the third and last baby.
pregnant
栏意味着母亲目前正怀着另一个尚未分娩的婴儿.
例如:
Helen has had three pregnancies.
Laura is currently pregnant so she has one pregnancy.
Mary would count as three pregnancies. Two that are in the past and one that is currently ongoing since the pregnant
column is true
.
我如何编写postgres查询?