performance - Save Conditional sum result in variable MySQL -


i stuck in query want store sum result in variable status = 3, happening right store value of last row , show rows

here query

    select  request_made_on,driver_id, @sum_result = sum(status = 3) complete_count,@sum_result, sum(status = 6) missed_count, (status = 4) canceled_count, sum(actual_fare),sum(discount)  tb_engagements  group date(request_made_on),driver_id; 

and here screenshot, second screenshot

i'm guessing want sum of values:

select request_made_on, driver_id,        (@sum_result := @sum_result + sum(status = 3)) complete_count,        sum(status = 6) missed_count,        sum(status = 4) canceled_count,        sum(actual_fare),        sum(discount) tb_engagements c cross join      (select @sum_result := 0) params group date(accept_time), driver_id; 

notes:

  • you don't need return value of variable expression. expression adds column result set value.
  • you don't need if() count values. mysql has nice short-hand, treating boolean expressions integers in numeric context.

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -