sql server - SQL Summarize and Group -


i have table in selecting following columns

work_role date_invoice bill_amnt 

i have multiple work roles invoiced @ multiple dates. summarize work role , see amount billed year on each column, 2014 , 2015.

something this:

work_role     bill_2014     bill_2015     p1            xxx,xxx       xxx,xxx    p3            xxx,xxx       xxx,xxx     e1            xxx,xxx       xxx,xxx 

use case expression conditionally sum bill_amnt depending on year:

select work_role,      sum(case when year(date_invoice) = 2014 bill_amnt end) "bill_2014",     sum(case when year(date_invoice) = 2015 bill_amnt end) "bill_2015" your_table group work_role 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -