php - Find sum of column with certain string(s) in another column in a table -


i trying work on project needs find total sum , total sum criteria. currently, have managed calculate total sum of column "price". here code:

$sumquery = "select sum(price) value_sum tickets"; //$dbc database connection $sumresponse = @mysqli_query($dbc, $sumquery); $sumrow = mysqli_fetch_array($sumresponse);  $sum = $sumrow['value_sum']; 

i want work upon code , make more specific. instead, want calculate sum of column "price" if in row has string "check" or "cash" in column "paytype". have no idea start this. have done research prior asking question, came out no results.

here snippet of table may understand more:

tickets table

here simple version of want achieve if description made no sense. find sum of column "price" each row string "check" or "cash" in column "paytype".

use conditional aggregation:

select sum(price) value_sum,        sum(case when paytype in ('check', 'cash') price end) check_or_cash tickets; 

of course, if want sum check/cash use where clause.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -