【发布时间】:2021-08-09 04:08:59
【问题描述】:
我需要根据另一个查询的结果自动生成列的值。因为这个列值必须是唯一的,所以我需要考虑并发请求。此查询需要为支持票证生成器生成唯一值。
唯一值的模板是CustomerName-Month-Year-SupportTicketForThisMonthCount。
所以脚本应该会自动生成:
- AcmeCo-10-2019-1
- AcmeCo-10-2019-2
- AcmeCo-10-2019-3
等等,因为支持票已创建。如果同时为 AcmeCo 创建两个支持票证,如何确保不会生成两次 AcmeCo-10-2019-1?
insert into SupportTickets (name)
select concat_ws('-', @CustomerName, @Month, @Year, COUNT())
from SupportTickets
where customerName = @CustomerName
and CreatedDate between @MonthStart and @MonthEnd;
【问题讨论】:
-
创建一个视图,其中包含一个具有窗口函数的新列。
标签: sql sql-server