So I have the following code
CREATE TABLE dispenser(
id_disp int not null auto_increment,
location_disp varchar(20) not null,
full_capacity int not null,
primary key (id_disp)
);
CREATE TABLE records(
time_stamp DATETIME DEFAULT CURRENT_TIMESTAMP not null,
id_dispenser int not null,
nr_pumps int not null,
primary key (id_dispenser,time_stamp)
);
CREATE VIEW left_capacity AS
SELECT
max(time_stamp) AS 'calendar',
id_dispenser AS 'dispenser',
full_capacity AS 'capacity',
(full_capacity-(nr_pumps*3)) AS 'available'
FROM records r, dispenser d
WHERE r.id_dispenser=d.id_disp
GROUP by id_dispenser
ORDER by id_dispenser desc;
and I have a problem on my view table where it says: (full_capacity-(nr_pumps*3)) because if nr_pumps*3 is bigger than full_capacity, I will have a negative available value. Is there a way I can make the value 0 if the calculation result is negative?