Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

Aggregate a column based on a value in another column- sql

$
0
0

I have a query which gives me the count by company/contractor, but now i need to modify it to include rows that have a value "1" in another column.

Query:

Select

         Date,

         process,

         Process Type,

          SUM(ISNULL(CAST(COMPANYCOUNT AS INT),0)) AS COMPANY
  SUM(ISNULL(CAST(CONTRACTORCOUNT AS INT),0)) AS CONTRACTOR

Output:

Date     Process           Process Type  Company Contractor

7/3/18  Service                 1              1              3

7/3/18 Service                  0              1               1

I want my output to give me the count by company/contractor when "Process Type" = "1". It should ignore all rows that have '0'.

Can someone help me how can i modify my SUM() statement to get this?


Viewing all articles
Browse latest Browse all 4729


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>