- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个触发器,将租车时间限制为 7 天。因此,例如......您可以在 01/01/2019 - 06/01/2019 期间租车,但是您不能在 01/01/2019 至 10/01/2019 期间租车。我使用 BEFORE INSERT 吗?感谢您的帮助。
为了清楚起见,我还附上了我的预订表。
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (1, '2019/02/26', '2019/02/28', '2019/03/01', 1, 1, 1, 1, 'Yes', 'Be a bit early');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (2, '2019/02/28', '2019/02/28', '2019/03/03', 2, NULL, 2, 2, 'No','Please have some water');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (3, '2019/03/01', '2019/03/02', '2019/03/05', 3, NULL, 3, 3, 'No','Drive slow, children in the car');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (4, '2019/03/04', '2019/03/06', '2019/03/10', 4, 4, 4, 4, 'Yes','Please be silent while driving');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (5, '2019/03/08', '2019/03/09', '2019/03/13', 5, NULL, 5, 5, 'No','Need to be exactly on time');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (6, '2019/04/03', '2019/04/04', '2019/04/06', 6, 6, 6, 6, 'Yes','Children onboard, please drive slow');
insert into bookings (booking_id, booking_date, start_date, end_date, invoice_no, chauffeur_id, vehicle_id, customer_id, chauffeur_req,special_instructions) values (7, '2019/04/05', '2019/04/07', '2019/03/10', 7, NULL, 7, 7, 'No','Arrive 5 minutes early');
最佳答案
我们可以在 BEFORE INSERT
触发器中执行此检查,并引发错误条件以防止语句在前面。为了完整起见,我们可能还需要一个 BEFORE UPDATE
触发器(以防止已经插入 bookings
的行被更改为超过一周。)
像这样开始:
DELIMITER $$
CREATE TRIGGER `trg_bookings_bi`
BEFORE INSERT ON `bookings`
FOR EACH ROW
BEGIN
IF ( NEW.end_date > NEW.start_date + INTERVAL 7 DAY ) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'error end_date more than seven days after start_date';
END IF;
END$$
DELIMITER ;
关于mysql - 触发器只允许租车最多 7 天 Max,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55364033/
看来我又被一个简单的正则表达式卡住了。 我想要什么: 1 到 999 之间的数字 可选:逗号、符号 如果输入逗号,最少1位小数,最多3位小数点应该是presebt。 Allowed: 100 999,
我需要从两列中获取最大值并将其发送到第三列。这些列的大小都是统一的,但有时大小会有所不同,但它们都将从同一个单元格开始。例如: 5 8 - 6 2 - 6 5 - 带有破折号的列需要找到其他两个之间的
我在我的网站上有一张包含用户排名列的表格,排名是一个数字,我想选择排名最高的 3 个用户,所以我查看并搜索了我认为最好的查询是那:Link (正确答案的第二个查询),但我不明白查询,如果有人能一步一步
我正在尝试制作一个点击计数器,我想收集 24 小时内的总点击次数。无论最终用户位于哪个时区,这 24 小时都应该是固定值。在 24 小时内,数据库应更新为 +1 次点击计数,一旦达到 24 小时时间范
我有一个在典型共享主机上运行的 PHP + MySQL Web 应用程序,我想知道调用最多的查询是什么以及消耗的资源量是多少。这样,我将专注于最昂贵的查询以优化资源或检测优化不佳的查询。 例如: qu
这是我“尝试”从用户输入的数字中找到最大 2 个值的代码: #include using namespace std; void maximum2(int a, int& max1,int& max
我需要编写一个 Python 函数,从具有最多“o”字符的字符串中返回单词。例如,get_most_ooo_word(['aa ao ooo']) 应该返回 ['ooo'] 和 get_most_oo
我正在寻找一种哈希算法,以创建尽可能接近字符串的唯一哈希值 (max len = 255),从而生成一个长整数 (DWORD)。 我意识到26^255 >> 2^32,但也知道英语的单词数远少于2^3
我得到了一个仅由 's','t','u','v' 作为字符组成的字符串 T。我想找到长度为 |T| 的字符串数它最多与 T 不同 n 个位置。而且每个这样的字符串在三个不同的位置不能有相同的字符,这些
我有一群“专家”(大约 300 人)可以胜任一项工作。而且我有很多工作必须完成,比如说大约 500 个。我也有信息,一个专家能做某项工作有多“好”。这将导致一个 300 x 500 的矩阵来保存权重。
我正在尝试解决这个问题,虽然我可以使用蛮力解决它,但是以下优化算法为我提供了一些测试用例的错误结果。我尝试了但无法找到代码的问题,任何人都可以帮助我。 问题:给定一个字符串 S 和整数 K,找到整数
我需要一个混合长度的正则表达式验证,总长度为 6 个字符,其中 4-6 个大写/数字字符和 0-2 个空格。 我试过 ^[A-Z0-9]{4,6}+[\s]{0,2}$ 但它导致最大长度为 8 个字符
我有一个数组 {-1,2,3,4,-3,-2,1,5} 现在我想找到给定数组的最小连续总和子数组,最多 K 次交换。 在上面的数组中,最小连续和是-5,子数组是{-3,-2} 对于 K=1 我应该如何
我们有一个简单的表格如下: ------------------------------------------------------------------------ | Name |
如果哈希不能超过 4 个字符,并且这 4 个字符只能是小写字母或数字,那么创建 String 哈希的最佳方法是什么? 我要散列的字符串有 1-255 个字符。我知道在没有冲突的情况下创建 4-char
我希望使用 Multipeer Connectivity 框架,并感谢任何关于如何最好地进行的经验之谈。 我需要在“教练”设备和最多 45 个“玩家”设备之间建立连接。他们都在同一个空间,但无法预测
给定一个数组 a,什么是实现其组合直到第 n 的最佳方法?例如: a = %i[a b c] n = 2 # Expected => [[], [:a], [:b], [:c], [:a, b], [
这个问题在这里已经有了答案: Formatting floats without trailing zeros (21 个回答) 关闭8年前。 我想格式化最多包含 2 个小数位的 float 列表。但
我无法使用以下形式的命令登录到远程 docker 注册表: docker login –u my-username –p my-password registry.myclient.com 我得到的错
所以这是我的代码:服务器.java import java.io.*; import java.net.*; import java.util.*; class Server implements R
我是一名优秀的程序员,十分优秀!