首页 > 解决方案 > 如何克隆表中的所有记录,同时将字符串添加到记录名称并增加记录 ID

问题描述

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

我现在需要做的是以下

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

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

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

编号:bf378ee4-2430-264a-e7ec-546e68b12301

编号:bf378ee4-2430-264a-e7ec-546e68b12302

编号:bf378ee4-2430-264a-e7ec-546e68b12303

不是这种情况

将数据复制到同一个表和从同一表复制数据,并将复制数据的一列中的值更改为指定值

用于创建新表

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 条记录 ALL WITH UNIQUE ID's no duplicates 其中 169 条在记录名称中添加了“复制”

标签: mysqlsqlmysql-workbenchsugarcrm

解决方案


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

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


推荐阅读