6 Replies Latest reply: Apr 8, 2013 11:04 AM by david.karr RSS

    Having trouble wrapping query as subquery in order to sum a column

      I have a query whose first column in the "select" is something like "count(distinct t.id)", and the query has a "group by" for several columns.

      This generates a number of rows with a number in the first column representing the number of distinct id values in the resulting group, and several other columns.

      I need to create a modified query that produces the sum of that first column.

      I figured this would look something like:

      select sum(total) from (select count(distinct t.id) as "total", ... from ... ... where)

      I'm not able to get this to work. It appears I can't refer to the alias from the parent query, but I've tried other ways of referencing that column value, and I just can't figure it out.

      I'd prefer not to have to provide the original query here. I'm hoping that I've provided enough information that someone could use to give me a useful response.