jeudi 23 avril 2015

Conditional Sum values in mysql query

i have a mysql table that contains services for invoices.

it looks like

servicename
ammount
price
tag (type of service)
discount(service worthy of discount, true or false)
clientDiscount (client worthy of discount, true or false)

I need to make a query that groups by year, sums(amount * price)

But, if discount and clientDiscount are true i need to count for a discount of 15%

I´ve tried with case and if statements but nothing works. I don't really know witch end to start in. And to be honest i can't really grasp how case and if statements work. I think i need to make one Sum that contains services with discount true and client discount true, then another sum that includes the services without discounts and add these upp to get a correct sum? Right now its like an ant farm in my head.

Aucun commentaire:

Enregistrer un commentaire