Avatar of Tom Wallace
Tom WallaceFlag for United States of America

asked on 

Sum based off condition

Hi all,


I am trying to create a column that will sum two other columns based off a condition & cannot seem to get it correct. for example heres what the data looks like:


CustomerID      Product   Sales   Sales2

1                          fruit          500

2                          veggi       100        200

3                          veggi       50           200   

4                           fruit         150


the goal is create a column called sales3 that when the product = fruit it will return the Sales column and when the product = veggi it will only return sales2 column.


what is the best way to achieve this?


thank you

Microsoft SQL Server

Avatar of undefined
Last Comment
Tom Wallace
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Tom Wallace
Tom Wallace
Flag of United States of America image

ASKER

oh wow I didn't think it would be so simple
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo