Re: getting sum of units sold in preceeding weeks

From: Nikhil (anonymous_at_discussions.microsoft.com)
Date: 05/11/04


Date: Tue, 11 May 2004 03:06:04 -0700

Well i did get that query..right sort off...
want one more help...

can i have the same in diff columns...e.g. the table column heading would be
item - week1 - week2 - week3

regards

Nikhil

     
     ----- Vishal Parkar wrote: -----
     
       hi nikhil,
     
       pls post sample data, table structure to get correct results. However you
     can have query as follows, replace dt_column with the name of the date
     columns you have and sold_units with the "units sold" column of your table.
     
       select
       select sum(case when dt_column >= dateadd(dd, -7, {fn current_date()} )
     and dt_column <= getdate() then sold_units else 0 end) 'last week',
       sum(case when dt_column >= dateadd(dd, -14, {fn current_date()} ) and
     dt_column < dateadd(dd, -7, {fn current_date()} ) then sold_units else 0
     end) '2nd last week'
       /*
       ... so on, add sum(CASE... statements to above query till the required
     date.
       */
       from
       <table_name>
     
       --
       Vishal Parkar
       vgparkar@yahoo.co.in | vgparkar@hotmail.com
     
     
     
     



Relevant Pages

  • Re: usb/cups printer problem after etch upgrade
    ... find /dev/ | sort> before.txt ... snoopy> diff -u before.txt after.txt ... configuration files during the upgrade. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: chester aftersales service
    ... I`ve had a nice email from Chesters and they are going to sort ... Best regards ... Stuff like the Adept lathes or some like the AA lathes from the US. ...
    (uk.rec.models.engineering)
  • Re: [PATCH] x86: Fix DMI out of memory problems
    ... i see no OOM messages in the diff - what am i missing? ... sort 2.6.24-rc5-patched> new.log ... audit: initializing netlink socket (disabled) ...
    (Linux-Kernel)
  • Re: New Elliott Randall CD (EP) ...and GUITAR DAY at my place
    ... Thanks you for the compliments! ... next couple of months - cover art is ready, ... Lotsa research as this is a Brave New World as regards this crazy ... what I sort of expected, very tasteful, funky,still got a sort of ...
    (uk.music.guitar)
  • Re: Treeview Node Type
    ... I've done this sort of thing a variety of ways. ... and less troublesome in regards to managing parent object references ... of type group nodes that want to different things to. ... Regards, Chris. ...
    (microsoft.public.dotnet.framework.aspnet)