MySql query sum rows based on other column value -


hey have weird logic can 1 me write query. want sum prices regoption regoption have xncoupon (coupon , regoption share same entry_id). in exaple wanted amount 139.

|id         |trans_id|  entry_id    |type     | price ------------------------------------------------------  |43575855   |24419612|  26898343    |regoption|  139          |43575856   |24419612|  26898343    |xncoupon |  50  |43575857   |24419612|  26898346    |regoption|  139          |43575858   |24419612|  26898346    |tshirt   |  10 

in second example wanted amount 278

|id         |trans_id|  entry_id    |type     | price ------------------------------------------------------  |43575855   |24419612|  26898343    |regoption|  139          |43575856   |24419612|  26898343    |xncoupon |  50  |43575857   |24419612|  26898346    |regoption|  139          |43575858   |24419612|  26898346    |xncoupon |  50 

my try this

select sum(price) table type ='regoption' , (something) check regoption related xncoupon same entry_id?

can me logic, welcomed

select sum(price)  table  type = 'regoption'  , entry_id in (     select entry_id      table      type = 'xncoupon' ) 

Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -