4 of 5
added 150 characters in body
SRI
  • 131
  • 8

SQL AVG and overall average of departments

my data is like this

Dept Sub_Dept Sal d1 sd1 100 d1 sd1 150 d1 sd2 100 d1 sd2 200 d1 sd2 350 d2 sd1 100 d2 sd1 250 d2 sd1 250 d2 sd2 200 d2 sd2 350

My output should be the count of each sub dept, the AVG of the Sal values of each sub department (sub_dept), and the AVG of all departments (dept)

I want my output to look like this

Result d1 sd1 2 125 d1 sd2 3 200 Total 5 180 d2 sd1 3 200 d2 sd2 2 225 Total 5 230 grand total 10 205

How to get the inner and outer AVG values ?

SRI
  • 131
  • 8