0

I have 3 'agentid' in this table. Now I want to find the max sum value of 'resolved' for 'agentid'.And also if i want to use where condition for specify 'reportyear' and 'reportmonth' then what should i do? i have...

$currentMonth = date('M'); $currentYear = date('Y');

How can I do it in laravel?

image of table

21
  • It's work's ....but i want to find the maximum value among them . Commented Dec 2, 2018 at 8:04
  • you want sum of resolved of each agent id and get the highest one ? Commented Dec 2, 2018 at 9:10
  • Yes,,, Highest one with his agent id Commented Dec 2, 2018 at 9:29
  • have you tried my answer? Commented Dec 2, 2018 at 9:31
  • yes.thanks.it's work's,but if i want to use where condition for specify 'reportyear' and 'reportmonth' then what should i do? i have $currentMonth = date('M'); $currentYear = date('Y'); Commented Dec 2, 2018 at 9:48

1 Answer 1

1

you want sum of resolved of each agent id and get the highest one ? If so then you can do something like this

$higest_resolved=DB::select(DB::raw('SELECT agentid,SUM(resolved) 
as resolved_total FROM table_name GROUP by agentid ORDER by resolved_total DESC LIMIT 1'));

for adding month and year condition,you can do as

$higest_resolved=DB::select(DB::raw('SELECT agentid,SUM(resolved) 
as resolved_total,reportyear,reportmonth FROM table_name where reportmonth="'.$currentMonth.'" and reportyear="'.$currentYear.'" GROUP by agentid,reportyear,reportmonth ORDER by resolved_total DESC'));

you can still add limit 1 at end to get only one value.

Sign up to request clarification or add additional context in comments.

Comments

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.