Re: Dynamic date range for each row?
- From: jefftyzzer <jefftyzzer@xxxxxxxxxxxxx>
- Date: Wed, 30 Jan 2008 09:55:31 -0800 (PST)
On Jan 29, 10:46 am, "lee.richmond" <Richm...@xxxxxxxxx> wrote:
Hi,
I'm trying to group data by date range, but each row of data could
have a different date range based on a variable.
I want to say "look at the date range the paste five orders were
placed" for each row individually. As an example, think of the rows as
keywords in a Search Marketing program. Keyword X had 5 orders placed
in the last week, Keyword Y had 5 orders placed in the last 2 weeks. I
want each keyword to display its average impressions over the course
of its respective date range.
Is this possible?
Thanks in advance!
Lee,
If (your version of) SQL Server implements them, you may want to look
at the windowing functions, and specifically the framing clause.
Here's an example of a simple moving average:
SELECT
keyword,
avg(qty) over (order by orderdate range between 5 preceding and
current row) as n
from
orders
The important part is the "range between 5 preceding and current row"
--Jeff
.
- Follow-Ups:
- Re: Dynamic date range for each row?
- From: Gert-Jan Strik
- Re: Dynamic date range for each row?
- References:
- Dynamic date range for each row?
- From: lee.richmond
- Dynamic date range for each row?
- Prev by Date: trig errors
- Next by Date: Re: Dynamic date range for each row?
- Previous by thread: Re: Dynamic date range for each row?
- Next by thread: Re: Dynamic date range for each row?
- Index(es):
Relevant Pages
|