How to get the Count of rows where either of two columns dates should be greater than a given date

I have a table which has two columns created_at and updated_at. These two columns store the date. Created_at stores the time when the row was created and updated_at stores the time when there was any updation in the row.

How to get the Count of rows where either of two columns dates should be greater than a given date

Now, I need to find out the number of rows which were either created at or updated at after a given ZonedTimeData.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can try OR statement to take the row whose created_at or updated_at is greater than the desired date.

Select count(*) from table
where (created_at >= '<yourDate>' OR updated_at >= '<yourDate>')

Method 2

You can give your DateTime value in the below <yourDate>. You can use below created_at or replace it with updated_at

select count(*)
from table
where created_at >= '<yourDate>'

Method 3

Just use a where clause:

select count(*)
from t
where created_at >= ? or updated_at >= ?;

Where ? is a parameter placeholder for the date/time value you care about.

Or, you might want where the last change was after a certain date:

select count(*)
from t
where coalesce(updated_at, created_at) >= ?;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x