mysql - 如何克隆表中的所有记录,同时将字符串添加到记录名称并增加记录 ID
问题描述
我通过将 2 个其他表与特定的 where 子句连接在一起创建了一个新表,这导致只有 169 条记录被添加到新表中。
我现在需要做的是以下
- 将所有这些记录克隆到当前表(DUPLICATE)
将字符串添加到当前记录名称示例原始记录名称:记录 1 克隆记录名称:记录 1 - COPY
记录都有唯一的 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 条在记录名称中添加了“复制”
解决方案
推荐阅读
- ios - 从通用 MTLBuffer 中读取内容?
- codeigniter - 错误号:1054 '字段列表'中的未知列 'sampledata'
- windows - 使用 pg_upgrade 从 PostgreSQL 10 升级到 12 时出错
- android - 更新到 Android Studio 4.0.1 版后,ADB 无法识别 USB 设备
- golem - 如何让 golem 应用程序出现在特定的 URL 路由中
- python - 重新启动 Django 服务器时,如何防止由 Django 进程生成的 websockify 进程被杀死?
- momentjs - Moment.js 没有显示正确的时间
- python - 如何在 python 中使用 for 循环向数组中添加一行?
- java - 我应该避免常用的类名吗?
- sql - 合并数据库时的主键冲突(自增)