40
WEEK
该天在所在的年份里是第几周。
EXTRACT(WEEK from TIMESTAMP '2001-02-16 20:38:40');
7
YEAR
年份域
EXTRACT(YEAR from TIMESTAMP '2001-02-16 20:38:40');
2001
数组函数;
| 函数 |
返回类型 |
描述 |
例子 |
结果 |
| array_cat(anyarray, anyarray) |
anyarray |
连接两个数组 |
array_cat(ARRAY[1,2,3], ARRAY[4,5]) |
{1,2,3,4,5} |
| array_append(anyarray, anyelement) |
anyarray |
向一个数组末尾附加一个元素 |
array_append(ARRAY[1,2], 3) |
{1,2,3} |
| array_prepend(anyelement, anyarray) |
anyarray |
向一个数组开头附加一个元素 |
array_prepend(1, ARRAY[2,3]) |
{1,2,3} |
| array_dims(anyarray) |
text |
返回一个数组维数的文本表示 |
array_dims(ARRAY[[1,2,3], [4,5,6]]) |
[1:2][1:3] |
| array_lower(anyarray, int) |
int |
返回指定的数组维数的下界 |
array_lower(array_prepend(0, ARRAY[1,2,3]), 1) |
0 |
| array_upper(anyarray, int) |
int |
返回指定数组维数的上界 |
array_upper(ARRAY[1,2,3,4], 1) |
4 |
| array_to_string(anyarray, text) |
text |
使用提供的分隔符连接数组元素 |
array_to_string(ARRAY[1, 2, 3], '~^~') |
1~^~2~^~3 |
| string_to_array(text, text) |
text[] |
使用指定的分隔符把字串拆分成数组元素 |
string_to_array('xx~^~yy~^~zz', '~^~') |
{xx,yy,zz} |
聚合函数:
1. AVG 返回指定组中的平均值,空值被忽略。
例:select prd_no,avg(qty) from sales group by prd_no
2. COUNT 返回指定组中项目的数量。
例:select count(prd_no) from sales
3. MAX 返回指定数据的最大值。
例:select prd_no,max(qty) from sales group by prd_no
4. MIN 返回指定数据的最小值。
例:select prd_no,min(qty) from sales group by prd_no
5. SUM 返回指定数据的和,只能用于数字列,空值被忽略。
例:select prd_no,sum(qty) from sales group by prd_no
6. COUNT_BIG 返回指定组中的项目数量,与COUNT函数不同的是COUNT_BIG返回bigint值,而COUNT返回的是int值。
例:select count_big(prd_no) from sales
7. GROUPING 产生一个附加的列,当用CUBE或ROLLUP运算符添加行时,输出值为1.当所添加的行不是由CUBE或ROLLUP产生时,输出值为0.
例:select prd_no,sum(qty),grouping(prd_no) from sales group by prd_no with rollup
8. BINARY_CHECKSUM 返回对表中的行或表达式列表计算的二进制校验值,用于检测表中行的更改。
例:select prd_no,binary_checksum(qty) from sales group by prd_no
9. CHECKSUM_AGG 返回指定数据的校验值,空值被忽略。
例:select prd_no,checksum_agg(binary_checksum(*)) from sales group by prd_no
10. CHECKSUM 返回在表的行上或在表达式列表上计算的校验值,用于生成哈希索引。
11. STDEV 返回给定表达式中所有值的统计标准偏差。
例:select stdev(prd_no) from sales
12. STDEVP 返回给定表达式中的所有值的填充统计标准偏差。
例:select stdevp(prd_no) from sales
13. VAR 返回给定表达式中所有值的统计方差。
例:select var(prd_no) from sales
14. VARP 返回给定表达式中所有值的填充的统计方差。
例:select varp(prd_no) from sales
15.统计各部门的总薪水,平均薪水和部门的详细情况
SELECTsum(salary) OVER (PARTITION by depname),avg(salary) OVER (PARTITION bydepname),*from empsalary;

16.统计人员在所在部门的薪水排名情况
select rank()over(partition by depname ORDER BY salary),* from empsalary;

select row_number() over(PARTITION by depnameZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcmRlciBieSBzYWxhcnkgZGVzYyksKiBmcm9tIGVtcHNhbGFyeTs8L3A+Cgo8cD7OqsO/0rvQ0Na4xcnSu7j2zqjSu7XEseC6xaGjyrnTw7TLuq/K/czmtPogTlVNQkVSILqvyv2hozwvcD4KPHA+PGltZyBzcmM9"https://www.cppentry.com/upload_files/article/57/1_gz83x__.png" alt="\">
select rank() over(partition by depname orderby salary desc),* from empsalary;
计算一个值在一组值中的排位。如果出现并列的情况,RANK 函数会在排名序列中留出空位。

select dense_rank() over(partition by depnameorder by salary desc),* from empsalary;
计算值在分区中的排位。对于并列的值,DENSE_RANK 函数不会在排名序列中留出空位。

select percent_rank() over(partition bydepname order by salary desc),* from empsalary;
根据rank()排序的第X行减去1除于组中总记录-1.

select cume_dist() over(partition by depnameorder by salary desc),