First post so sorry! I have:
| PARTICIPANT | VALUE | RULE | PERIOD |
|---|---|---|---|
| JAMES | 0 | RULE 1 | 2022-12-1 |
| JAMES | 0 | RULE 1 | 2022-01-1 |
| JAMES | 1 | RULE 1 | 2022-02-1 |
| JAMES | 1 | RULE 2 | 2022-12-1 |
| JAMES | 1 | RULE 2 | 2022-01-1 |
| JAMES | 1 | RULE 2 | 2022-02-1 |
I want:
| PARTICIPANT | VALUE |
|---|---|
| JAMES | 1 |
I tried:
SELECT [PARTICIPANT], SUM([VALUE]), [Period]
FROM (
SELECT [PARTICIPANT], [VALUE], [RULE], [Period]
FROM [TABLE]
WHERE [RULE]='RULE 1'
UNION
SELECT [PARTICIPANT], [VALUE], [RULE], [Period]
FROM [TABLE]
WHERE [RULE]='RULE 2'
) AS [T1]
GROUP BY [Participant], [Period]
I have four columns [Participant, Value, Rule and Period] There are only two types of [Rule].
I want to Select the participant's value for each Period only if the value of Rule 1 is >= to value of Rule 2.
I am not sure how to denote the comparison since each participant has multiple periods and each period may or may not have both rules.
I also want to sum the value of the selected periods by participant to perform functions on later.