这是我正在使用的查询代码,请查看并帮助我。我真的很感激
DB::table('position as p') -> addSelect(\DB::raw(
'p.*,(SELECT name from user where user.id=p.user_id) as name'
))
-> addSelect(\DB::raw(
'DATE_FORMAT(p.created_at,"%H:%i") as time'
))
-> whereRaw($wr)
-> whereRaw(
"(p.id =(SELECT id FROM position WHERE position.user_id=p.user_id AND Date(position.created_at)='".$date.
"' order by position.id asc limit 0,1) Or p.id =(SELECT id FROM position WHERE position.user_id=p.user_id AND Date(position.created_at)='".$date.
"' order by position.id desc limit 0,1))")
-> orderBy("p.user_id", "asc") - > orderBy("p.id", 'asc') - > get();