sql去重多个字段(伪)、gp数据库的插⼊语句、更新时间(没有毫秒)
源表:
select distinct id , name, phone from chongfubiao_quchong;
select distinct * from chongfubiao_quchong;
distinct(*)命令 #语法错误
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) from chongfubiao_quchong' at line 1
distinct(id)查出来的是⼀列
select distinct (id,name,phone) from chongfubiao_quchong;
[Err] 1241 - Operand should contain 1 column(s)
查询多个字段去重
参考链接:
参考命令:select distinct ID,AA,BB from tName
之前查询⽆论
distinct (单个字段)还是
distinct 多个字段好像查询到的数据都是根据多个字段去重的。不知道怎么查询显⽰了?
INSERT into chongfubiao_quchong_copy (id, nam, phone)
select distinct *  from chongfubiao_quchong  ;
写的错误语句
INSERT into chongfubiao_quchong_copy (id, nam, phone) values
select distinct *  from chongfubiao_quchong  ;
多了values 因为查到的是有id,name,phone还有数据
如果直接插要加values的
INSERT into chongfubiao_quchong_copy (id, nam, phone) values
(5, '3', '4')
sql语句的功能有#每个字段查询
select distinct 列1名 , 列2名.. from 表名;
#所有查询
select distinct * from 表名;
#插⼊⼀条数据
INSERT into 插⼊表 (列1名 , 列2名..) value
(数据1,数据2,..) ;
#插⼊多条数据
INSERT into 插⼊表 (列1名 , 列2名..) values
(数据1,数据2,..) ,(数据1,数据2,..);
#插⼊查询到的数据
INSERT into 插⼊表 (列1名 , 列2名..)  # 括号中东西不能⽤*替换
select distinct *  from 查询表  ;
在Navicat中复制⼀个表,并粘贴⼀个。很快1m 600w数据(3列)(写语句也⼀样)下⾯的是去重了之后插⼊的先查询在插⼊
[SQL]INSERT (id,xm,sfzh,jymc,jyjg,jgmc,jysj) SELECT distinct * ;时间: 13.450s
受影响的⾏: 6796168
679w数据(函id、姓名、⾝份证号)的查询和插⼊另⼀个表⽤时13s。。。。SELECT distinct * ;
select 字段 from 表 group by 字段 having count(字段 ) >1;
UPDATE 更新表 SET sj = current_timestamp(0);
已经有数据的表为什么没法通过设置默认为current_timestamp(0)来添加时间。
还需要加update
series 序列即使有数据也可以添加进去⾃增的序列。