SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Grouping records by time interval


Grouping records by time interval

Author
Message
geert.de.vylder
geert.de.vylder
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 141
ChrisM@Work (3/6/2013)

I meant in terms of potentially reducing the rowcount.
Let's call a set from this table containing the same day, all of the intervals, and the same Event_Channel, a frame. One frame contains 96 rows, one row per interval. There are 9 event channels so there are 864 rows per date. Multiply 864 by the number of dates in the tickets table - 1366 - to yield the number of rows in the matrix table.
One possibility is to remove frames which don't have any corresponding rows in the tickets table.


Sorry,

I misunderstood you.
Then the best would be to work with a variable of the datetime type and set this variable to a fix date (for example 2013-03-01 YYYY-MM-DD format) or to set it to yesterdays date. And then retreive the frame for all 9 event channels.

Would that be better?

Greetz,

Geert
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16808 Visits: 19557
geert.de.vylder (3/6/2013)
ChrisM@Work (3/6/2013)

I meant in terms of potentially reducing the rowcount.
Let's call a set from this table containing the same day, all of the intervals, and the same Event_Channel, a frame. One frame contains 96 rows, one row per interval. There are 9 event channels so there are 864 rows per date. Multiply 864 by the number of dates in the tickets table - 1366 - to yield the number of rows in the matrix table.
One possibility is to remove frames which don't have any corresponding rows in the tickets table.


Sorry,

I misunderstood you.
Then the best would be to work with a variable of the datetime type and set this variable to a fix date (for example 2013-03-01 YYYY-MM-DD format) or to set it to yesterdays date. And then retreive the frame for all 9 event channels.

Would that be better?

Greetz,

Geert


I've no idea, Geert. Folks here on SSC will help you with coding decisions; this is more of a business decision. A date filter seems sensible to me but is it appropriate for the consumers of the data? How many days' worth of data are other folks expecting to see?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
geert.de.vylder
geert.de.vylder
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 141
ChrisM@Work (3/6/2013)


I've no idea, Geert. Folks here on SSC will help you with coding decisions; this is more of a business decision. A date filter seems sensible to me but is it appropriate for the consumers of the data? How many days' worth of data are other folks expecting to see?


We would like to see a month worth of data. Let's say February.
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16808 Visits: 19557
geert.de.vylder (3/6/2013)
ChrisM@Work (3/6/2013)


I've no idea, Geert. Folks here on SSC will help you with coding decisions; this is more of a business decision. A date filter seems sensible to me but is it appropriate for the consumers of the data? How many days' worth of data are other folks expecting to see?


We would like to see a month worth of data. Let's say February.


How about "all data for last month - which as of today will be February"?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16808 Visits: 19557
geert.de.vylder (3/6/2013)
ChrisM@Work (3/6/2013)


I've no idea, Geert. Folks here on SSC will help you with coding decisions; this is more of a business decision. A date filter seems sensible to me but is it appropriate for the consumers of the data? How many days' worth of data are other folks expecting to see?


We would like to see a month worth of data. Let's say February.


There's no data in the table for February :-P

-- last month:
SELECT
MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-1,0), -- 1st Feb
MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate()),0) -- 1st Mar

-- month before last:
SELECT
MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-2,0), -- 1st Jan
MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- 1st Feb

-- Usage:
SELECT *
FROM Tussen_Tickets
WHERE Ticket_Closed_DateTime >= DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- greater than or equal to
AND Ticket_Closed_DateTime < DATEADD(month,DATEDIFF(month,0,getdate()),0) -- LESS THAN



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
geert.de.vylder
geert.de.vylder
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 141
ChrisM@Work (3/6/2013)


There's no data in the table for February :-P

-- last month:
SELECT
MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-1,0), -- 1st Feb
MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate()),0) -- 1st Mar

-- month before last:
SELECT
MonthStart = DATEADD(month,DATEDIFF(month,0,getdate())-2,0), -- 1st Jan
MonthEnd = DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- 1st Feb

-- Usage:
SELECT *
FROM Tussen_Tickets
WHERE Ticket_Closed_DateTime >= DATEADD(month,DATEDIFF(month,0,getdate())-1,0) -- greater than or equal to
AND Ticket_Closed_DateTime < DATEADD(month,DATEDIFF(month,0,getdate()),0) -- LESS THAN



I do get 160 rows for february from the Tusen_Tickets table. But this is the Original not aggregated table Tussen_Tickets.
I'm getting desperate now, because I dont get any result from the last query with the 2 temp tables.
ChrisM@Work
ChrisM@Work
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16808 Visits: 19557
SELECT MAX(Ticket_Closed_DateTime)
FROM Tussen_Tickets

-- returns '2013-01-17 10:22:00.000'

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search