[英]MySQL ids by proper series
We are building an invoice management app and need help/suggestions with the following... 我们正在开发一个发票管理应用程序,需要以下帮助/建议...
We want your suggestions to achieve this. 我们希望您的建议能够实现这一目标。 thanks. 谢谢。
you need compound primary key. 您需要复合主键。 eg: 例如:
year int
invoice_id int
select ... where date_of_record between $start_of_period and $end_of_period
. 只需为每个记录存储一个“创建时间”时间戳,然后确定客户端中的过滤规则,然后只需select ... where date_of_record between $start_of_period and $end_of_period
。 Create the primary key as in heximal's answer. 按照十六进制答案创建主键。 Then use this to insert a new id: 然后使用它插入新的ID:
insert into my_table (id, year)
values (
coalesce (
(
select new_id = max(id) + 1
from my_table
where year = @year
), 1)
, @year
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.