Skip to content
Advertisement

check if record exists in previous date and not in current date in the same table and return count of records matched and unmatched

I am trying to get the count of records that were there in one date and also in another date. What would be the most efficient way?

id date
AB 6/11/2021
AB 6/11/2021
BC 6/04/2021
BC 6/04/2021
AB 6/04/2021
AB 6/04/2021

This should return True =2 (Ab is present in 04/21) and False=2

Advertisement

Answer

Per ID if it’s in more than one other date is a COUNT DISTINCT

gives:

ID COUNT(DISTINCT DATE) > 1
AB TRUE
BC FALSE

thus the number of things in this state is:

giving:

COUNT_IF(C)
1

and if you like to see that in a form where there is a table:

the selecting ID can be dropped on that:

Ah, I think your comment you are asking for:

C COUNT(*)
TRUE 1
FALSE 1

Another way to think about it:

gives:

ID DATE COUNT_SAME IN_MANY
AB 6/11/2021 2 TRUE
BC 6/04/2021 2 FALSE
AB 6/04/2021 2 TRUE

but if you are want just one row per ID, and to know if they are in many dates that is simple, but what to make of the fact you want the id/date count across those many rows, when folded up.

The description of desired output is rather vague..

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement