0

I have a working SQL query.

SELECT stuid,grade,SUM(full_amount) FROM due_payments group by stuid having SUM(full_amount) !=15600

This is working fine in MySQL workbench and phpmyadmin,But i cant seems to get this work in Laravel 5.3

I tried this on Laravel app with no Luck

$someVariable = Input::get(15600);

$results = DB::select( DB::raw("SELECT stuid,grade,SUM(full_amount) FROM due_payments 
                group by stuid having SUM(full_amount) =:somevariable)", array(
        'somevariable' => $someVariable,
)));

Can someone Help me with this.Thank You.

2 Answers 2

1

First if all Input::get() doesn't take value as argument but the element name
$someVariable = Input::get(15600);
You can just use $someVariable = 15600;

Then use Query Builder rather than Raw SQL query

     $results = DB::table('due_payments')
     ->select(array('stuid', 'grade', DB::raw('SUM(full_amount)'))) 
     ->groupBy('stuid')
     ->havingRaw('SUM(full_amount) != '.$someVariable)
     ->get();
Sign up to request clarification or add additional context in comments.

Comments

1

Use query builder.

$results = DB::table('due_payments')
        ->select('stuid', 'grade',DB::raw('SUM(full_amount)'))
        ->groupBy('stuid')
        ->havingRaw('SUM(full_amount) != 15600')
        ->get();

1 Comment

glad it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.