Re: SELECT by quarter of hour

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Itzik Ben-Gan (itzik_at_REMOVETHIS.SolidQualityLearning.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 06:24:14 -0500

Simon, here's one way to achieve this (untested):

select dt as fromtime, dateadd(mi, 15, dt) as totime,
  sum(quantity) as totalqty, sum(qty1) as totalqty1
from (select
        dateadd(mi, datediff(mi, '20000101', getdate())
          /15*15, '20000101') as dt,
        quantity,
        case when type = 1 then quantity end as qty1
      from t1) as d
group by dt

-- 
BG, SQL Server MVP
www.SolidQualityLearning.com
"simon" <simon.zupan@stud-moderna.si> wrote in message 
news:uu9b5Ig1EHA.2876@TK2MSFTNGP12.phx.gbl...
>I have table SELL with columns: 
>productID(varchar(20)),quantity(int),type(tinyInt),sellDate(datetime)
>
> I would like to get  sum of sell for one day, devided by quarter of hour 
> for all products and for only products where type=1.
>
> The result should be like his:
>
> time                    sum(quantity)            sum(quantity where 
> type=1)
> ---------------------------------------------------------------------
> 0-0.15                    1000                                300
> 0.15-0.30                200                                 120
> 0.30-0.45                566                                 322
> 0.45-1                     222                                 29
> 1-1.15                     50                                   17
> 1.15-1.30                0                                      0
> .....and so on
> ....until
> 23.45-24.00
>
> Any idea?
>
> Thank you,
> Simon
>
> 


Relevant Pages

  • FS Larrivee Parlor, La Patrie Etude
    ... Simon & Patrick. ... I have debated whether or not to sell these, ... nice guitars in very good condition, but I really want that Simon & ... Patrick for myself. ...
    (rec.music.makers.guitar.acoustic)
  • Re: Distance learning "A plus" question
    ... I have opened the packet that the CD came in ... ... >> Next thing you'll be asking these guys to sell you a bit of paper ... do things then there will always be someone popping up to sell it to ...
    (uk.comp.homebuilt)
  • Re: Rubbish explorer
    ... > Simon wrote in uk.sport.football.clubs.liverpool on Thursday 22 December ... >> Remember the BS don't have morals. ... They'd sell their fucking granny ...
    (uk.sport.football.clubs.liverpool)
  • Re: Another Amplifone thread!
    ... This seems like a lot of work for them to only sell a 300 or so flybacks so cheap. ... both Simon and Mark may not know about. ... Then I literally lost it within all of my ... etc. just like Simon says that the 1st version had. ...
    (rec.games.video.arcade.collecting)
  • Re: OT:Headphones with a 2.5mm Jack
    ... >> Any suggestions of shops that sell them or recommendations of online ...
    (uk.rec.motorcycles)