Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
newToSqI
Starting Member
2 Posts |
Posted - 2011-01-17 : 14:31:23
|
| Hi community,I'm trying to run a script that will count all rows for a certain period of time in example below only January submissions. However, some of those rows have the same date and I want to have the latest time row of that day in the count. Could anyone give me a hand with this?Thanks,Oracle 10gsample 'submit' tablepk submit_time1 1/17/2011 08:05:23 AM2 1/17/2011 07:59:53 AM3 1/14/2011 05:25:35 PM4 1/05/2011 01:06:12 PM5 12/18/2010 4:34:12 PM |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-01-17 : 14:40:11
|
| DECLARE @Table TABLE (pk int,submit_time datetime)INSERT INTO @TableSELECT 1 ,'1/17/2011 08:05:23 AM' UNION ALLSELECT 2,'1/17/2011 07:59:53 AM' UNION ALLSELECT 3,'1/14/2011 05:25:35 PM' UNION ALLSELECT 4,'1/05/2011 01:06:12 PM' UNION ALLSELECT 5,'2/18/2010 4:34:12 PM'SELECT count (distinct datepart(day,submit_time))FROM @tableWHERE submit_time >= '20110101' and submit_time < '20110201'JimEveryday I learn something that somebody else already knew |
 |
|
|
newToSqI
Starting Member
2 Posts |
Posted - 2011-01-17 : 15:23:44
|
| Hi,Thanks for the quick reply, wow.so use a temporary table basically and use the distinct statement to pull the 'one' i want to use in my count.this is easy enough for a handful of submissions. Any idea on how to make something like this when having to check tens of thousands of records? |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-01-17 : 15:31:34
|
| I only used a table variable so I'd have data to work with, you can replace @Table in my query with 'submit' for yours.JimEveryday I learn something that somebody else already knew |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-18 : 08:47:58
|
| If you use ORACLE, you need to post the question at ORACLE forums such as www.orafaq.comMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|