Posted by Emmanuel, Feb. 13, 2024, 5:46 a.m.
Treatment of duplicates
I have the following database:
| Variable_1 | Variable_2 | |
| CompanyA | 100 $ | 200 $ |
| CompanyA | 100 $ | 250 $ |
| CompanyA | 100 $ | 80 $ |
| CompanyB | 125 $ | 25 $ |
| CompanyB | 125 $ | 50 $ |
| CompanyB | 125 $ | 45 $ |
| Total | Variable_1 | Variable-2 |
| CompanyA | ||
| CompanyB |
My question is the following:
What is the codes (sql) to calculate the total for companyA and CompanyB: For variable_1, I must take the first line (100 $for companyA and 125 $ for companyB) to avoid the double or triple counting while for variable_2 I must make a total of every thing for each company (200 $+250 $+80 $ for companyA and 25 $+50 $ + 45 $ for company B).
Thank you.