How do I query this

I have two tables which I want to count how many items recorded after a certain date.
How to I make a query for this.

Table 1:


Table 2:

id1     id2     id3     id4     date
1       1       0       1       2015-07-31 18:51:53
2       1       0       1       2015-08-01 16:20:37
3       1       0       2       2015-08-05 18:54:29
4       1       0       3       2015-08-06 14:02:18
5       1       0       3       2015-08-06 14:02:18
6       1       0       3       2015-08-06 14:02:39

I’m not sure if I want 2 tables. The values 1 in column id2 of table 2 is the id of table 1.
The id3 values are all 0 because something is error which I have to investigate and not sure if it will be used in this.

My point of interest is id4 column. It’s the user id.
I want to know how many other users make record after a certain date, in this case, assumed 2015-08-01.
I want to count only how many users make record after id 1 person.
Data suggest that id 2 made 1 record and id 3 made 3 record after the id 1 did it.
How to count how many people that do the record for certain id2 items after the first people do it. This should apply to people having id = 2 and id = 3 as well.
How to tell them that record has been added by other people.
Or if this is not possible, is there any way to tell them if there other people do something after they did.

Hope I explain it clearly.

What have you tried thus far?

Some hints which might push you in the right direction

  • To get the count of something, you need to use SELECT COUNT
  • You can check a date based using the > or < depending on if you want it to be before or after a date.
  • I hope your date field isn’t called date. That’s a reserved word. You CAN use it if you escape the name (i.e. ‘date’ or [date] depending on the DBMS), but it’s just bad practice.
  • You’ll want to use a sub query to pull the date for id1. You could use a different query type, but (for me at least), the sub-query is the easiest way to go.

Thanks, I found solution on the internet.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.