CREATE TABLE `cars` (
`regnum` varchar(10) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`brand` varchar(20) NOT NULL,
`model` varchar(20) NOT NULL,
`type` tinyint(1) UNSIGNED NOT NULL,
`color` varchar(14) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`fuel` tinyint(1) UNSIGNED NOT NULL,
`year` int(4) UNSIGNED NOT NULL,
`mileage` int(10) UNSIGNED NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `rental` (
`id` int(5) NOT NULL,
`car` varchar(10) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`user_id` int(5) UNSIGNED NOT NULL,
`price` decimal(19,2) NOT NULL,
`pick_up_location` varchar(20) NOT NULL,
`drop_out_location` varchar(20) NOT NULL,
`start_date` date NOT NULL,
`end_date` date NOT NULL,
`remark` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
start_date > CURRENT_DATE()
)SELECT DISTINCT c.* FROM cars c join rental r on c.regnum = r.car where r.start_date > CURRENT_DATE()
select *
from cars
where not exists (
select 1
from rental
where
rental.car = cars.regnum
and CURRENT_DATE() between start_date and end_date
);
select *
from cars
where exists (
select 1
from rental
where
rental.car = cars.regnum
and CURRENT_DATE() between start_date and end_date
);
select *
from cars
where exists (
select 1
from rental
where
rental.car = cars.regnum
and start_date > CURRENT_DATE()
);