views:

45

answers:

2

I used pivot to get data in format

Store  department  Employee     Q1         Q2         Q3
----------------------------------------------------------
abc      d1         u1          1          Null       Null
abc      d1         u1          Null       3          Null
abc      d1         u1          Null       Null       2     
abc      d1         u2          1          Null       Null
abc      d1         u2          Null       3          Null
abc      d1         u2          Null       Null       2   
abc      d2         u1          1          Null       Null
abc      d2         u1          Null       3          Null
abc      d2         u1          Null       Null       2    

I want to group them as

Employee             Q1         Q2         q3
------------------------------------------------------------------
u1                   1           3        2
u2                   1           3        2

How can i achieve this using sql query or is it possible to directly do it using pivot

A: 

Assuming PIVOTED is the table or query that produce the data you showed

select employee, avg(Q1) as Q1, avg(Q2) as Q2, avg(Q3) as Q3
from PIVOTED
group by employee

Of course avg could not be the right grouping (min? max?). Tell us more.

momobo
A: 

I changed my query so that i don't have to group and get result as desired

rs