Hi,
I have a rather complex logical query I'm trying to execute. Essentially there are a series of related tables. I am having difficulty figuring out a good way to approach it.
Tables:
Transaction -
T_id
Discount -
D_id
item_id
Type (percentage or basic value)
value
Transaction_Discount -
T_id
D_id
Item -
item_id
price
EDIT: additional table
Purchase
T_id
item_id
I am attempting to pull the price adjusted after the discount is applied. I would like to avoid adding another column with the adjusted price to the database... as it is possible to calculate the adjusted price for each transaction from the data already entered (so it'd be redundant to store this data).
This is the basic logic:
if(this transaction had a discount applied)
//apply the discount and return the adjusted price
else(no discount applied)
//pull price
It is possible to do this in several separate queries using PHP logic.
//1st step - create an array of bool's: true = discount_used/false = no_discount
//2nd step - if(discount_used) return price adjusted to discount
//3rd step - if(no_discount) return price
//4th step - combine the two different arrays
this is clearly very bulky. It seems like there HAS to be a better way to do this that is likely much more efficient.
It is my understanding that you can perform queries that contain logic in mysql, would that help here?