1、修改字段中文名称
ALTER TABLE tablename CHANGE doc_rev_ind doc_rev_ind varchar(40) comment \'收取要求\'
2、增加一列
ALTER TABLE tablename add columns (IS_AUTH VARCHAR(8) comment\'是否实名认证0未实名 1已实名\')
3、删除一列
ALTER TABLE tablename drop ACTIVE_LENGTH
4、删除分区
ALTER TABLE tablename drop if exists partition(dt = \'20190520\')
ALTER TABLE tablename drop partition ( dt !=\'20201105\')
5、查询列的信息
DESCRIBE tablename
6、查询建表语句
SHOW CREATE TABLE tablename
7、concat 拼接两个字符串
select concat(\'zhang\',\'077\')
结果:zhang077
8、group_concat 将group by产生的同一个分组中的值连接起来,返回一个字符串结果
首先看一下这个查询结果值:SELECT DISTINCT ID_TYP,MTD_CDE FROM RTDW.LC_APPL
然后运行:SELECT ID_TYP,GROUP_CONCAT(ID_TYP,MTD_CDE) FROM (SELECT DISTINCT ID_TYP,MTD_CDE FROM RTDW.LC_APPL ) T GROUP BY ID_TYP
9、建表
CREATE TABLE IF NOT EXISTS TEMP_WEIXIN_RECONCILIATION( `RECONCILIATION_PK` VARCHAR(80) COMMENT \'主键\' ,`APP_ID` VARCHAR(80) COMMENT \'公众号ID\' ,`MCH_ID` VARCHAR(80) COMMENT \'商户号\' ,`RECONCILIATION_STS` VARCHAR(40) COMMENT \'对账状态 01: 未对账 02:已对账\' ) PARTITIONED BY ( DT VARCHAR(8) COMMENT \'数据日期\' ) COMMENT \'账单临时表\' ROW FORMAT DELIMITED FIELDS TERMINATED BY \'\001\' LINES TERMINATED BY \'\n\' STORED AS TEXTFILE
10、COALESCE如果时null值则转换成空(‘’)
COALESCE(T1.DEVICE_ID,\'\')
11、CAST字段类型转换
CAST(T1.ID AS VARCHAR(64) )
12、查看一张表对应的文件
show files in tablename
13、把时间戳转换成秒数
select unix_timestamp(now())
14、把秒数转成时间戳
select from_unixtime(cast(cast(1000.0 as decimal) as bigint));
15、把字符串转换成时间戳
cast(\'2019-10-14 18:00:41\' as timestamp)