Re: Dynamic date range for each row?



I assume you are looking for something beyond just retrieving the last
five orders - say using the data in the Orders table to control the
data being retrieved from some other table entirely.

This gets the date range for the most recent five orders by customer.

SELECT CustomerID,
MIN(OrderDate) as StartDate,
MAX(OrderDate) as EndDate
FROM Orders as A
WHERE OrderID IN
(SELECT TOP 5 B.OrderID
FROM Orders as B
WHERE A.CustomerID = B.CustomerID
ORDER BY B.OrderDate DESC)
GROUP BY CustomerID

I will leave it to you to apply that data to whatever table is
required.

Roy Harvey
Beacon Falls, CT

On Tue, 29 Jan 2008 10:46:47 -0800 (PST), "lee.richmond"
<Richmolj@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!
.



Relevant Pages

  • Re: Dynamic date range for each row?
    ... I'm trying to group data by date range, but each row of data could ... Keyword Y had 5 orders placed in the last 2 weeks. ... at the windowing functions, ... The important part is the "range between 5 preceding and current row" ...
    (comp.databases.ms-sqlserver)
  • Re: Creating a search function on a table
    ... Have you examined queries? ... MS Access MVP ... The tables are linked by customer number, ... > a keyword and return all addresses that contain this keyword. ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Return whole word for filtering
    ... linked it to the Customers Table on their PK long integer IDs. ... would use a Join to identify the Customer Records with Key Word sport. ... attempt at keyword searches several years ago. ... I didn't do the information web site at the main company I work for. ...
    (comp.databases.ms-access)
  • Re: Dynamic date range for each row?
    ... I'm trying to group data by date range, but each row of data could ... Keyword Y had 5 orders placed in the last 2 weeks. ... want each keyword to display its average impressions over the course ... The important part is the "range between 5 preceding and current row" ...
    (comp.databases.ms-sqlserver)
  • Dynamic date range for each row?
    ... I'm trying to group data by date range, but each row of data could ... Keyword Y had 5 orders placed in the last 2 weeks. ... want each keyword to display its average impressions over the course ...
    (comp.databases.ms-sqlserver)