vendredi 24 juin 2016

Can I create a view that needs to calculate its variables using multiple variables from multiple tables?

So I am trying to learn how to work with databases and php but I have run into some trouble concerning whether I can make a view for what i need or if i would just need to get all the variables into a php function and calculate it there.

Here is the database structure i have decided for the project. (The premise is setup a database and webpage for a truck rental company if it helps.)

Vehicles(vehicleId, size, gas)

Price(size, price)

Customer(customerId, firstname, lastname, streetaddress, city, state, zipcode, email, company)

Rental(rentId, customerId, vehicleId, startdate, enddate, tank(0=full positive=number of gallons missing from tank), damage(0=none))

So the view in this example i am trying to create would calculate the total cost for each rental for easy display

total cost is price of specific vehicle size * number of days rented (if returned on same day is 1) + (tank * 5) + damage

The view would also contain the rentalId, and customerId to make it simple to search for total amount spent.

can i do this in mysql or would it need to be done in php?

Aucun commentaire:

Enregistrer un commentaire