20160509 GreenPlum3 基本语法

来源:互联网 发布:我欲封天晋级数据 编辑:程序博客网 时间:2024/06/05 23:39

以下是工作中用到的语法总结,会不断补充:

1 复制他表的结构,不指定分布健那么默认分布健和xh1一样

    #create table xh(like xh1);

    #select * into xh from xh1;

    #create table xh as select * from xh1;

2 清空表:

   常用的是drop,会连标题也清掉

   也可以truncate,会清掉表中的内容,但是表头会留下来。

3 将两列合并成一列输出,合并的是列名

   #update xh_ie_2 set 机型=TERMBRAND_NAME||TERMTYPE_NAME;  

   将具体的内容合并

   #select 'green'||'plum'  as dbname;

4 用  |   将单词分开

    #values('hello|world!'),('greenplum|database');

5 关于截取字符

   获取某段字符:#select substr('hello',2,3);

   获取字串位置:#select position('world' in 'hello world');   ---7

6 时间加减,interval表示时间间隔的数据类型,两个时间的差就是一个interval类型

   # select '2011-10-01 10:0:0' :: timestamp + interval '10 days 2 hours 10 seconds';            ---2011-10-11 12:00:10

7 获取当前时间

   # select now() , current_date,current_time,current_timestamp;

8 获取当月第一天

   #select date_trunc('months',now())::date;

9  获取当前时间距离2011-10-10 10:10:10过了多少秒

   #select extract(epoch from now()- '2011-10-10 10:10:10');

10 取绝对值函数

   #select abs(-12);        ---12

11 指数

   #select exp(1);            ---2.71828182845905 

 

12 大小写转换函数

   #select upper('erlonglong');----ERLONGLONG

   #select lower('ERLONGLONG');   ---erlonglong

 

13 查询否定结果时:

   not放在where之后where not

   where A note between x and y;

   where A not in ('a','b');

 

 

 

 

 

 

 

0 0
原创粉丝点击