删除重复行 error 1093

删除重复行和error 1093


解决1:直接删除(拥有自动增长的cust_id列)

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BYcust_name)as a);

 

解决2:删除重建

create table tmp   (select a.* from customers a,

     (select min(cust_id) as cust_id from `customers` group by cust_name)  b where a.cust_id=b.cust_id);

create table tmp2 select min(cust_id) as cust_id,

cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country,cust_contact,cust_email

from`customers` GROUP BY cust_name;

create table tmp1 select distinct * from customers_copy;    //没有自动增长id列,采用这种方法

 

drop table customers;

rename table tmp to customers;

 



我在创建过程中出现了一个如下报错:

1093错误:You can'tspecify target table 'perf_linux_t' for update in FROM clause 

解决:将子查询变为孙子查询,再嵌套一个查询,一定要定义别名

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BY cust_name) as a); 

 

附:

//查看表中的重复行信息

select cust_name from (SELECT cust_name,count(*) FROM `customers` GROUP BY cust_name having count(*)>1);

 

//若没有自动增长的id列,可以添加

ALTER TABLE `perf_linux_t` ADD COLUMN `auto_id`INT NOT NULL AUTO_INCREMENT primary key;

 



如果大家还有更好的方法,望高手指点。

我在创建过程中出现了一个如下报错:

1093错误:You can'tspecify target table 'perf_linux_t' for update in FROM clause 

解决:将子查询变为孙子查询,再嵌套一个查询,一定要定义别名

delete from `customers` where cust_id not in

     (select cust_id from (select min(cust_id) as cust_id from `customers` GROUP BY cust_name) as a); 

 

附:

//查看表中的重复行信息

select cust_name from (SELECT cust_name,count(*) FROM `customers` GROUP BY cust_name having count(*)>1);

 

//若没有自动增长的id列,可以添加

ALTER TABLE `perf_linux_t` ADD COLUMN `auto_id`INT NOT NULL AUTO_INCREMENT primary key;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在C语言中去除重复的文本可以通过以下步骤实现: 1. 读取文本文件中的每一数据并存储到一个字符数组中。 2. 对于每一数据,使用一个哈希表或者集合来判断该数据是否已经出现过。 3. 如果该数据没有出现过,则将其输出到一个新的文本文件中,并将其添加到哈希表或者集合中。 4. 最后关闭原始文件和新文件。 下面是一个示例代码,可以实现去除重复的功能: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LEN 1024 int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s input_file output_file\n", argv[0]); return 1; } char *input_file = argv[1]; char *output_file = argv[2]; FILE *in_fp = fopen(input_file, "r"); if (in_fp == NULL) { printf("Error opening file %s\n", input_file); return 1; } FILE *out_fp = fopen(output_file, "w"); if (out_fp == NULL) { printf("Error creating file %s\n", output_file); return 1; } char line[MAX_LEN]; int line_count = 0; // 使用哈希表来存储出现过的数据 int hash_table[100000] = {0}; while (fgets(line, MAX_LEN, in_fp) != NULL) { line_count++; // 计算哈希值 int hash_value = 0; for (int i = 0; i < strlen(line); i++) { hash_value = (hash_value * 31 + line[i]) % 100000; } // 如果该数据已经出现过,则跳过 if (hash_table[hash_value] == line_count) { continue; } // 将该数据输出到新文件中 fprintf(out_fp, "%s", line); hash_table[hash_value] = line_count; } fclose(in_fp); fclose(out_fp); return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值