Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

how to make this smart query?

$
0
0
In the following table we record studentname, lecture_subject and presenting_date.
table: studentlectures
Code:

ID  studentname          subject,    lecturedate
1        john          politics,      1/1/12
2        steve        politics,      16/1/12
3        steve          economics,    21/1/12
4        steve        politics,        22/1/12
5        john            economics,    22/1/12
6        john          politics,        25/1/12
7        john          politics,        3/2/12

We need a query to remove a lecturer who was presented less than a month on the same subject and by the same student. So we will get the following result:
Code:

ID  studentname          subject,          lecturedate
1        john            politics,          1/1/12
2        steve          politics,          16/1/12
3        steve          economics,          21/1/12
5        john            economics,          22/1/12
7        john            politics,          3/2/12

As you see records 4 and 6 are not shown because the same subject is presented by the same student in less than 30 days after the date when that subject was presented by the same student. For example record 6 is not shown because john had presented politics only 24 days before. Can we make this query?
Thank you,

Viewing all articles
Browse latest Browse all 13329

Trending Articles