Skip to content
Advertisement

SQL Grouping within Sub Queries

I am trying to group multiple columns based on a case statement.

My current code is as follows :

The results look like this :

What I want is to roll up all Market and and lihtc/pha into one group so the results would look like :

  PropNumber   propname                detail_group    UnitCount   MoveIns
gsaff       Gardens at South Bay, LTD (gsaff)   Market            20    0
gsaff       Gardens at South Bay, LTD (gsaff)   LIHTC/PHA         79    4 

The actual data in the unit type is m1,m2, m3 and tc1, tc2,etc so that is the cause for the multiple lines when linking back in the subquery on ut1.scode = ut.scode. I also realize i can only return one value in the subquery so am guessing i need to somehow use an exist within the where statement to accomplish this.

Advertisement

Answer

If the results of your query are correct, then all you need is group by on that query:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement