Had one query where we have to give count of Surgeries done in the order of Speciality (Department), OT type, OT Category, OT Sub-Category. We wrote a simple SQL Query with Group by clause. So we were getting records like: (Example)
Speciality Type Category Sub-category count
CTVS Closed Heart Congenital Interrupted Aortic Arch 456
CTVS Closed Heart Congenital Ventricular Septal Defect 678
CTVS Closed Heart Ischemic Interrupted Aortic Arch 123
CTVS Closed Heart Ischemic Ventricular Septal Defect 465
CTVS Open Heart Congenital Interrupted Aortic Arch 138
CTVS Open Heart Congenital Ventricular Septal Defect 615
CTVS Open Heart Ischemic Interrupted Aortic Arch 513
CTVS Open Heart Ischemic Ventricular Septal Defect 908
So, how to get Counts at all the three levels: Type, Category and Sub-category?
The trick was in use of CUBE
Syntax: group by cube(column1, column2, column3,...,columnn)
and then it gave the output, the way we wanted
Speciality Type Category Sub-category count
CTVS Closed Heart Congenital Interrupted Aortic Arch 456
CTVS Closed Heart Congenital Ventricular Septal Defect 678
CTVS Closed Heart Congenital................................................... 1134
CTVS Closed Heart Ischemic Interrupted Aortic Arch 123
CTVS Closed Heart Ischemic Ventricular Septal Defect 465
CTVS Closed Heart Ischemic...................................................... 588
CTVS Closed Heart......................................................................... 1722
CTVS Open Heart Congenital Interrupted Aortic Arch 138
CTVS Open Heart Congenital Ventricular Septal Defect 615
CTVS Open Heart Congenital.................................................... 753
CTVS Open Heart Ischemic Interrupted Aortic Arch 513
CTVS Open Heart Ischemic Ventricular Septal Defect 908
CTVS Open Heart Ischemic....................................................... 1421
CTVS Open Heart ........................................................................... 2174
Cool...So, now no more struggling with multiple totals :)
preventing Moodle time-outs
5 days ago
I am sure you would have noticed that the subtotal rows have a 'null' value at the level in which subtotalling. You can make this a little more readable to the user by using the IsNull Function [ IsNull(Column_Name, Value_If_Null] and displaying a word like say, 'Subtotal', instead of a boring blank null. :)
ReplyDeleteYes Naams,
ReplyDeleteI did observe that...will try out the option suggested and come back with an update into post
R
Thought i might add that Excel could do such a small thing...not trying to milk the brains of Software guys (they are much in demand and are needed elsewhere). This is a short guided tour by Microsoft in creating Pivot tables and consolidating the data. See if it is useful!
ReplyDeletehttp://office.microsoft.com/training/training.aspx?AssetID=RC102058721033&CTT=6&Origin=RP102058711033