I have a table which consists of multiple columns.
Table consists of data like
Group no | Maxtime | Updatedtime |
---|---|---|
A22 | 20221502 | 20221702 |
A22 | 20212502 | 20221702 |
A22 | 20212502 | 20221702 |
I query that table with a condition like
Select Group no from cnt where maxtime<=updatedtime
The output comes A22
Now I want to use this output to query the same table again and get the count of A22 which is 3 with a condition in where clause where I use other columns of the table.
Something like
Select count(group no)
From cnt
Where (effdate<candate)
Effdate and candate are columns of the same table.
2
Answers
Use
GROUP BY
to get the counts of each group. And combine both conditions withAND
.I suppose you want this: count the rows with effdate < candate for each group_no for which exists a row with maxtime <= updatedtime.