Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

laravel5.2 的sql语句问题

数据库结构如下所示

clipboard.png

course表
clipboard.png

sc表

clipboard.png

student表

clipboard.png

laravel的sql语句代码

$get_all = sc::leftJoin("student", "sc.sid", "=", "student.snum")
            ->Join("course", "sc.cid", "=", "course.cno")
            ->where('sc.cid', '=', $id)
            ->where(number_format('sc.grade',2), '=', $max)
            ->get();

因为sc表中的成绩是用float类型存储的,所以必须对sc表进行取到小数点后两位需要进行number_format处理,,,,但是最大的问题就是报错

clipboard.png

想要达到的效果是通过传过来的课程id和成绩的max值,来获取对应的学生信息,,感觉可以把成绩的max值去掉直接通过课程id值来获取课程最高成绩的学生信息,,,但是不知道怎么做。。。。还望大神指点,,,,什么方法都行


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...