<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sum Query Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/sum-query/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/sum-query/</link>
	<description>Code Solution</description>
	<lastBuildDate>Thu, 20 Jan 2022 10:41:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>Sum Query Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/sum-query/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sum Query with Where Condition In Laravel 8</title>
		<link>https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/</link>
					<comments>https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 20 Jan 2022 10:41:46 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Sum Query]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1396</guid>

					<description><![CDATA[<p>Hi Dev, Today, i we will show you sum query with where condition in laravel 8. This article will give you simple example of sum query with where condition in laravel 8. you will sum query with where condition in laravel 8. In this article, we will implement a sum query with where condition in &#8230; <a href="https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/" class="more-link">Continue reading<span class="screen-reader-text"> "Sum Query with Where Condition In Laravel 8"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/">Sum Query with Where Condition In Laravel 8</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>Today, i we will show you sum query with where condition in laravel 8. This article will give you simple example of sum query with where condition in laravel 8. you will sum query with where condition in laravel 8. In this article, we will implement a sum query with where condition in laravel 8. </p>
<p>So let’s follow few step to create example of sum query with where condition in laravel 8.</p>
<h3 class="step_code">Example 1: using having()</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  
namespace App\Http\Controllers;
  
use App\Models\User;
use DB;
  
class UserController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $users = UserPayment::select(&quot;*&quot;, DB::raw('SUM(amount) as total'))
                    -&gt;groupBy(&quot;user_id&quot;)
                    -&gt;having('total', '&gt;', 50)
                    -&gt;get();
  
        dd($users);
    }
}
</pre>
<p><strong>Output:</strong></p>
<pre class="brush: xml; title: ; notranslate">
Array

(

    &#x5B;0] =&gt; Array

        (
            &#x5B;id] =&gt; 1
            &#x5B;user_id] =&gt; 1
            &#x5B;amount] =&gt; 56
            &#x5B;payment_date] =&gt; 2022-01-04
            &#x5B;status] =&gt; 1
            &#x5B;created_at] =&gt; 
            &#x5B;updated_at] =&gt; 
            &#x5B;total] =&gt; 56
        )

    &#x5B;1] =&gt; Array

        (
            &#x5B;id] =&gt; 2
            &#x5B;user_id] =&gt; 2
            &#x5B;amount] =&gt; 45
            &#x5B;payment_date] =&gt; 2022-01-07
            &#x5B;status] =&gt; 0
            &#x5B;created_at] =&gt; 
            &#x5B;updated_at] =&gt; 
            &#x5B;total] =&gt; 55
        )

)
</pre>
<h3 class="step_code">Example 2: using havingRaw()</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
  
namespace App\Http\Controllers;
  
use App\Models\User;
use DB;
  
class UserController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $users = UserPayment::select(&quot;*&quot;, DB::raw('SUM(amount) as total'))
                    -&gt;groupBy(&quot;user_id&quot;)
                    -&gt;havingRaw('total &gt; 50')
                    -&gt;get();
  
        dd($users);
    }
}
</pre>
<p><strong>Output:</strong></p>
<pre class="brush: xml; title: ; notranslate">
Array

(

    &#x5B;0] =&gt; Array

        (
            &#x5B;id] =&gt; 1
            &#x5B;user_id] =&gt; 1
            &#x5B;amount] =&gt; 58
            &#x5B;payment_date] =&gt; 2022-01-04
            &#x5B;status] =&gt; 1
            &#x5B;created_at] =&gt; 
            &#x5B;updated_at] =&gt; 
            &#x5B;total] =&gt; 56
        )

    &#x5B;1] =&gt; Array

        (
            &#x5B;id] =&gt; 2
            &#x5B;user_id] =&gt; 2
            &#x5B;amount] =&gt; 45
            &#x5B;payment_date] =&gt; 2022-01-07
            &#x5B;status] =&gt; 0
            &#x5B;created_at] =&gt; 
            &#x5B;updated_at] =&gt; 
            &#x5B;total] =&gt; 55

        )
)
</pre>
<p>I hope it will assist you…</p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/">Sum Query with Where Condition In Laravel 8</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/sum-query-with-where-condition-in-laravel-8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
