Pokud mi v požadavcích něco nechybí, proč nepoužít agregační funkci s GROUP BY
:
select state, month, id, sum(sales) Total
from yourtable
group by state, month, id
order by id
Výsledek je:
| STATE | MONTH | ID | TOTAL |
--------------------------------
| FL | July | 1 | 10000 |
| FL | June | 1 | 21000 |
| CA | April | 32 | 2000 |
| MI | April | 32 | 13000 |
| TX | January | 50 | 1000 |