mysql loop to create single output -


the problem

i have table 'purchase' index salespersonnumber, productcode , purchaseid. productcode acts foreign key table 'product' there index price.

there table 'purchase info' key offerprice. table composed of composite key keys productcode , purchaseid.

i wanting able add every price salespersonnumber = x if offerprice > 0 row add total (instead of price).

is there way go doing mysql?

the atempt

setting connections other tables:

select *  `purchase`  inner join `product` on purchase.productcode = product.productcode inner join `purchase info` pi on purchase.productcode = pi.productcode , purchase.purchaseid = pi.purchaseid 

the final statement

where salespersonnumber = "'.$x.'" 

now need come loop?

pseudo code

for each(number of rows belonging salespersonnumberx row){     if(row['offerprice'] > 0){         row['price'] = row['offerprice'];     }     total += row['price']; } return total; 

ts & cs

this needs solely done in sql!!†

apart variable $x

yes.

without digging deeper schema, easy answer is, use case statement.

https://dev.mysql.com/doc/refman/5.0/en/case.html


Popular posts from this blog