I
I
ichernob2015-07-20 10:47:54
SQL
ichernob, 2015-07-20 10:47:54

What query is needed to count the number of rows in the sample that satisfies the given condition?

There is a table - the result of the selection, for example
ShopId ShopCode ShopSeq
13500 q109190 1
12679 q109190 1
217 q109190 2
For a record with a given ShopId, you need to count the number of rows in the table whose ShopSeq is less than the ShopSeq of a record with a given ShopId. For example, for an entry with ShopId = 217, the number 2 should be returned, for ShopId = 12679, the number 0 should be returned.
Here's what I managed to compose myself:

COUNT (CASE WHEN ShopSeq < someNumber then 1 end) as X

I just can’t figure out how to substitute ShopSeq from a line with a given ShopId instead of someNumber.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2015-07-20
@ichernob

well, replace your someNumber with (Select ShopSeq from Table where ShopId='217')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question