Looking for percentage of aggregate, grouped on column value



I'm trying to write a query that will give me a column's (sum(value) in
a date range) as a percentage of that column's sum(value) for all
records, and grouped by a column of types. Something like 'give me #1,
the sum of all values for a column, and #2 the sum of values for the
same column where {some other value) is >= X and <= Y, and then divide
2 by 1 and give the answer to me as a percentage of 1.

The table is fairly vanilla, e.g:

dept
product#
sale_date
price
quant
total

I can plug in different values myself but I'm certainly getting the
construction wrong because I can't seem to build anything mysql wants
to use. Does it take a sub-query? Self-join, outer join, temp duplicate
table?

Thanks for any pointers,

r

.



Relevant Pages

  • Re: Optimising the Query
    ... SUM ... FROM TABLE3 ... The query is taking records from TABLE2 and TABLE3 and LEFT OUTER JOIN ...
    (comp.databases.oracle.misc)
  • Re: Trying to optimize a query with a bunch of INNER JOINs
    ... It can help to put the meat of the query in the derived table and then do ... A right outer join is just a left outer join turned around, ... Pro SQL Server 2000 Database Design - ... and it's taking just as long as with the sum. ...
    (microsoft.public.sqlserver.programming)
  • Re: Looking for percentage of aggregate, grouped on column value
    ... > the sum of all values for a column, and #2 the sum of values for the ... Self-join, outer join, temp duplicate ... I don't know mysql, but if it supports views,then build your result set ... can access the same table more than once in a query, IOW, yes a self ...
    (comp.databases)
  • calculating SUM
    ... I have the following query that I'm trying to get SUM values. ... In the SELECT clause I can calculate horizontally. ... ItemPrice.OrderNo RIGHT OUTER JOIN dbo.SaleGroups ON ItemStock.OrderNo = ...
    (microsoft.public.sqlserver.programming)
  • Re: Report is making too many numbers
    ... from the $'s being listed more than once in the query. ... And you want to display the sum of in the Vendor header or footer ... My report is based on a query. ... those records--you could create a Totals query by depressing the ...
    (microsoft.public.access.reports)