troubleshooting Question

SQL query to count records before they change

Avatar of rwallacej
rwallacej asked on
Microsoft SQL Server 2008
26 Comments1 Solution530 ViewsLast Modified:
Hi

I have a problem with SQL query.   I want to display the first record and the number of times a value is duplicated before the next uniqu record. An example of input data

date field   value         other fields.....
---------------------------------------
01:00       1234        
01:01       1234
01:02       1234
01:03       654
01:04        321
01:05        321
01:06        1234

The results I would like to display:

Date field                           Value        Count of records
(first time value occurs)
----------------------------------------
01:00                                 1234              3
01:03                                 654              1
01:04                                 321              2
01:06                                 1234            1

Not that I don't want a count of e.g. 1234 over all record set but counts as the values change

Thank-you in advance for help in SQL.
ASKER CERTIFIED SOLUTION
Sharath S
Data Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 26 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 26 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros