我的问题非常简单的表现就是:取得成果取决于基于时间的条件
评论
| mentor_id | mentee_id | status | created |
| 1 | 2 | active | 2014-08-13 |
| 1 | 2 | inactive | 2014-08-20 |
| 1 | 2 | inactive | 2014-08-27 |
| 1 | 3 | inactive | 2014-08-20 |
| 1 | 2 | inactive | 2014-09-03 |
用户表
| id | first_name | last_name |
| 1 | Ivan | Pietro |
| 2 | Alexander | Summers |
| 3 | Mark | Xavier |
学长表
| id | mentee_id | mentor_id | created |
| 1 | 2 | 1 | 2014-08-06 |
| 2 | 3 | 1 | 2014-08-06 |
mentor_id
和mentee_id
是用户表的ID。
我想要得到的users.id
,users.first_name
和users.last_name
具有的inactive
在过去14天status
他们在辅导表创建后的学弟学妹(user
表)。
在哪里存储这些评论?你需要选择你想要的w/e,在mentee_id上加入用户表,然后按创建顺序排列,并且限制为2。 – Solrac 2014-10-01 08:17:43
[SQL Counting Records with Count and Having]的可能重复(http://stackoverflow.com/questions/4912792/sql-counting-records-with-count-and-having) – bodi0 2014-10-01 08:19:47
评论存储在评论表 – 2014-10-01 08:23:43