Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query help

Status
Not open for further replies.

Bell1991

Programmer
Aug 20, 2003
386
US
I have a table that has date and total number of orders. I need to return something that looks like this:

Date Total
5 12/2/08
10 12/1/08
585 Total for November
51 11/30/08
80 11/29/08
.....

Is this possible?

I can get this information in two queries:

Select dtDate, numOrders
from tblTotalOrders
order by dtDate desc

Select year(dtDate) as year, month(dtDate) as month, sum(numOrders)
group by year(dtDate), month(dtDate)
order by year,month desc

Any guidance you can provide would be most grateful.

Thanks in advance



 
Code:
SELECT yyyy, mm, dd
     , SUM(numOrders)
  FROM (
       SELECT YEAR(dtDate) AS yyyy
            , MONTH(dtDate) AS mm
            , DAY(dtDate) AS dd
            , numOrders
         FROM tblTotalOrders 
       ) AS d
GROUP
    BY yyyy, mm, dd 
WITH ROLLUP

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top