我的查询在mysql中工作但不适用于laravel eloquent

时间:2016-03-19 12:36:09

标签: mysql eloquent laravel-4.2

Laravel查询:

$studentsFee = \FeeModal::query();
$studentsFee->groupBy('main_campus_id', 'session_id', 'class_info_id', 'section_id', 'stage_id')
                ->selectRaw('count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount')
                ->with('sessionMode', 'section',  'classInfo', 'stage')->get();

dd(count($studentsFee). ' Records' );

结果:  0记录

->toSql();生成的查询

string(281) "select count(student_id) as student_strength,SUM(IF(paid_amount>0,1,0)) as submit_students,SUM(IF(paid_amount=0,1,0)) as not_submit_students, sum(paid_amount) as submit_amount from `fee` group by `main_campus_id`, `session_id`, `class_info_id`, `section_id`, `stage_id`" 

当我在mysql中执行此查询时,它返回18行;

1 个答案:

答案 0 :(得分:0)

我认为您忘记将查询结果分配给变量:

def main():
    # create a list
    myList = []

    number_of_values = input('Please enter number of values: ')

    # Display the total of the list  elements.
    print('the list is: ', create_list(number_of_values))
    print('the total is ', get_total(myList))

    # The get_total function accepts a list as an
    # argument returns the total sum of the values in
    # the list

def get_total(value_list):

    total = 0

    # calculate the total of the list elements
    for num in value_list:
        total += num

    #Return the total.
    return total

def create_list(number_of_values):

    myList = []
    for num in range(number_of_values):
        num = input('Please enter number: ')
        myList.append(num)

    return myList

main()