你好,我想按日期获取评估1的最新结果和评估2的最新结果。如:
|id| name | assessment| date |Course_code
| 1|jon |1 |2014-01-01 |1
| 2|jon |1 |2014-01-05 |1
| 3|jon |1 |2014-01-01 |2
| 4|jon |2 |2014-01-01 |1
| 5|jon |2 |2014-01-11 |2
| 6|jon |2 |2014-01-14 |1
| 7|jon |2 |2014-01-01 |1
| 8|jon |1 |2014-01-11 |1
在这里,我想获得单个查询构建中的最新评估2和最新评估1。我在这里使用的是laravel 4
DB::table('result')->where('username','jon')->where('course_code','1')->where('assignment_no',1)->orderBy('date','Desc')->limit(1)->get();
i为评估1和评估2分别完成,我可以在一个单一的查询建筑上得到结果吗?
您可以使用whereIn()
,如下所示:
DB::table('result')
->where('username','jon')
->where('course_code','1')
->whereIn('assignment_no', [1, 2]) // you simply supply an array of values
->orderBy('date','Desc')
->limit(1)
->get();
当然,除非你也改变限制,否则你仍然只能得到一行。
我假设"评估"是一个错别字,因为你的代码中有"assignment_no"