I have a system to calculate a payment of fines to a user, this has the following two tables: FINES and FINES_USERS
NOTES:
// In the table fines I have inserted the two types of fines, both normal and special, just change their type. (explained later)
// It is only possible to insert a type of fine for users, either normal or special.
TABLE OF FINES:
fine_type: one-digit integer, 1 = normal fine, 2 = special fine
num_multa: different numbers of fines for each corresponding fine
value: value of the fine
description_mult: describe the fine
Example:
fine_type: 1 num_mult: 1 value: 500 description_mult: walk out of grated
fine_type: 1 num_mult: 2 value: 1500 fine_ description: cross in red
fine_type: 1 num_mult: 3 value: 1300 description_mult: I disrespect the transit officer
fine_type: 2 num_mult: 1 value: 1000 description_mult: run through the grated
fine_type: 2 num_mult: 2 value: 2000 description_mult: crash and run away
fine_type: 2 num_mult: 3 value: 1700 description_mult: hit the transit officer.
TABLE OF FINES_USERS:
user_id: user identification number
fine_type: foreign key of the type of fine
multa_num: number of the fine
Example
user_id: 25171777 fine_type: 1 multa_num: 1
user_id: 25171777 fine_type: 1 multa_num: 2
userid: 12412421 fine_type: 2 multa_num: 1
userid: 12412421 fine_type: 2 multa_num: 2
I would like to be able to get the total value of the fine knowing that for each user you must add the values that correspond to each fine that has saved in FINES_USERS .
Taking an example:
User: 25171777:
type of fine: 1, number: 1 (brought from MULTAS_USUARIOS ), value: 500 ( brought from FINES )
type of fine: 1, number: 2 (brought from MULTAS_USUARIOS ), value: 1500 ( brought from FINES )
Total fines = 2000
That's why I need the SQL statement to get those values and add them, and also the formula that should be used
MANY THANKS