gpt4 book ai didi

mysql - 如何克隆表中的所有记录,同时向记录名称添加字符串并递增记录 ID

转载 作者:行者123 更新时间:2023-11-29 15:43:48 25 4
gpt4 key购买 nike

我通过将另外 2 个表与特定的 where 子句连接在一起创建了一个新表,这导致只有 169 条记录被添加到新表中。

我现在需要做的是以下

  1. 将所有这些记录克隆到当前表(重复)
  2. 将字符串添加到当前记录名称例子原始记录名称:记录1克隆记录名称:记录 1 - COPY

  3. 所有记录都有唯一的 ID,克隆时,ID 应该递增,但不能与其他记录的其他 ID 相同。

注意:这个新表中的记录不是下面的连续示例

ID:bf378ee4-2430-264a-e7ec-546e68b12301

ID:bf378ee4-2430-264a-e7ec-546e68b12302

ID:bf378ee4-2430-264a-e7ec-546e68b12303

事实并非如此

Copy data to and from the same table and change the value of copied data in one column to a specified value

用于创建新表

create table sgr_New.tim_time_temp_merged_and_purged as
SELECT * from sgr_New.tim_time as T
join sgr_New.tim_time_cstm as C
on T.id = C.id_c
where
(C.billable_time_c > "0")and
(C.unbillable_time_c > "0")and
(C.unbillable_reason_c not like "No_Unbillable_Time");

在网上找到这个(相关吗)对于冗长的查询,我必须指定所有字段,因为有一个我不应该插入的特定字段,对此表示歉意。

insert into sgr_new.tim_time_temp_merged_and_purged (c1, c2, ...)
select
unpaid_billable_revenue_c,
unbilled_hours_c,
unbillable_time_c,
unbillable_reason_c,
training_time_c,
touched_c,
total_time_c,
time_netsuite_id_c,
time_entered_c,
tag_c,
requirements_time_c,
reporting_time_c,
related_account_c,
project_rate_c,
project_or_case_name_c,
project_number_c,
project_mgmt_time_c,
platform_build_time_c,
overrun_c,
num_minutes_c,
num_hours_c,
internal_notes_c,
free_hours_c,
expense_calculation_c,
expense_amount_c,
duration_c,
dev_time_c,
date_performed_c,
data_load_time_c,
currency_id,
counter_field_c,
configuration_time_c,
category_c,
case_rate_c,
case_number_c,
billing_rate_override_c,
billing_rate_c,
billing_notes_c,
billed_time_c,
billable_time_wf_copy_c,
billable_time_override_c,
billable_time_c,
billable_override_c,
billable_hours_kpi_c,
billable_c,
billable_amount_c,
base_rate,
amount_c,
account_short_name_c
from sgr_new.tim.time_cstm
where id = 1;

我期待看到我的表中的 338 条记录全部具有唯一 ID,没有重复项其中 169 个在记录名称中添加了“复制”

最佳答案

有一个mysql函数UUID() (在 MSSQL 中: LOWER( NEWID() ) )您可以不带参数调用它来生成正确格式的 ID。

对于名称,只需使用CONCAT(),但我看到你已经自己找到了它:)

关于mysql - 如何克隆表中的所有记录,同时向记录名称添加字符串并递增记录 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57301095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com