你好,全部來自所有國家。 我需要一個SQL查詢轉換爲LARAVEL 4.2因爲我還沒有經驗來管理它,我自己!SQL微軟查詢到Laravel 4.2
的SQL是SQL服務器微軟2008
SELECT TOP(10) logst_data, LogSt_date, LogSt_studid FROM Home_LogStudents WHERE logst_action = 225 AND LogSt_sectionID = 257 AND LogSt_date IN (SELECT MIN(LogSt_date) FROM Home_LogStudents WHERE logst_data <> '0' AND logst_action = 225 AND LogSt_sectionID = 257 AND (LogSt_studid IN (select home_id FROM Hw_StudentClasses INNER JOIN Home_Students ON home_studid = Stclass_studid WHERE Stclass_classid = (129))) GROUP BY LogSt_studid) ORDER BY LogSt_data DESC
所有我能做的就是在接下來的圖片:enter image description here但$ ID和$類標識碼不 可在$查詢中識別....也是代碼:
$users = DB::Table('Home_LogStudents')
->select('LogSt_data','LogSt_date','LogSt_studid')
->where('LogSt_action','=',225)
->where('LogSt_sectionID','=',$id)
->whereIn('LogSt_date',function($query){
$query->select('LogSt_date')
->from('Home_LogStudents')
->where('LogSt_data','!=',0)
->where('LogSt_action','=',225)
->where('LogSt_sectionID','=',$id)
->whereIn('LogSt_studid',function($query){
$query->select('home_id')
->from('Hw_StudentClasses')
->join('Home_Students','Home_Students.home_studid','=','Hw_StudentClasses.Stclass_studid')
->where('Stclass_classid','=',$class_id);
}
)
->groupBy('LogSt_studid');
})
->orderBy('LogSt_data','DESC')
->take(10)
->get();
謝謝您提前,只爲尋找!
我想你應該在這裏發佈的不是照片 – hungneox
你的代碼,但基本上你需要使用'($類標識碼)',因爲匿名函數不能識別外部範圍變量。 – hungneox
你的意思是用$查詢把$ id放在第一個子查詢中,在第二個子查詢中放$ class_id? –