Suppose I have the following table T1
:
| col1 | col2 |
|------|------|
| 0 | 0 | // A++
| 3 | 123 | // B++
| 0 | 5 | // C++
| 8 | 432 | // A++
| 0 | 4 | // B++
I now need to create a trigger (on INSERT
), that analyses every row, increases a counter (see below), populates the table T2
with the values of the counter:
IF col1 = 0 AND col2 = 0
A++
ELSE IF col1 = 0 col2 > 0
B++
ELSE IF col1 > 0
C++
In this case, T2
would look like:
| id | A | B | C |
|----|---|---|---|
| 1 | 1 | 2 | 2 |
My question is more about the design: Should I really iterate through each row, as described HERE, or is there a more efficient way?