Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count records until a record value changes

Status
Not open for further replies.

BobThornton

Programmer
Sep 12, 2022
12
US
Thanks in advance for all of your help, it is greatly appreciated!

I want to count the number of 'N' ANSWER records until the value of ANSWER changes the first time.
So in below the count would equal 3
How can I do this?
Please see below

ID ANSWER DATE RANKING
12345 N 11/7/2022 1
12345 N 10/7/2022 2
12345 N 9/9/2022 3
12345 Y 8/5/2022 4
12345 N 7/1/2022 5
12345 N 6/3/2022 6
12345 N 5/6/2022 7
12345 N 4/1/2022 8
12346 Y 4/2/2022 9
12347 Y 4/3/2022 10
12348 Y 4/4/2022 11
12349 Y 4/5/2022 12
12350 Y 4/6/2022 13
 
i tried this
Code:
select min(RANKING)-1 as NUMBER_OF_N_ANSWERS
from MYTABLE
group by ANSWER
having ANSWER = 'Y'
 
SELECT MIN(ranking) - 1 AS initial_nos
FROM my_table
WHERE answer = 'Y';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top