9.15. �ۼ�����

�ۼ����� ��һ������ֵ�����һ������� Table 9-37 ��ʾ���ڽ��ۼ������� �ۼ������������﷨�� Section 4.2.7����͡���ο� Part I ��ȡ���ӵĽ�������Ϣ��

Table 9-37. �ۼ�����

������������������������
avg(expression) ��������ֵ�ľ�ֵ������ƽ���� smallint, integer, bigint, real, double precision, numeric, �� interval. �����κ������������룬������� numeric ���͡� �����κθ������룬������� double precision ���͡� �������������������ͬ�� ��������ֵ��ƽ��������ƽ������
bit_and(expression) smallint, integer, bigint, ���� bit �Ͳ�������������ͬ ���зǿ�����ֵ�İ�λ AND ���룩�����û�У���Ϊ��
bit_or(expression) smallint, integer, bigint, ���� bit �Ͳ�������������ͬ ���зǿ�����ֵ�İ�λ OR ���򣩣����û�У���Ϊ��
bool_and(expression) bool bool �����������ֵ�����棬��Ϊ�棬����Ϊ��
bool_or(expression) bool bool ���������һ������ֵΪ�棬��Ϊ�ţ�����Ϊ��
count(*) bigint����ֵ�ĸ���
count(expression)����bigint ������Щ expression �� NULL ������ĸ�����
every(expression) bool bool ���� bool_and
max(expression)�κ���ֵ���ִ���������/ʱ�����������ͬ������������ֵ�У� expression �����ֵ
min(expression)�κ���ֵ���ִ���������/ʱ�����������ͬ������������ֵ�У� expression ����Сֵ
stddev(expression) smallint, integer, bigint, real, double precision, �� numeric. ����������ʱ��double precision�� ���� numeric�� ����ֵ�ı�׼����ƫ�sample standard deviation��
sum(expression) smallint, integer, bigint, real, double precision, numeric, ���� interval �� smallint �� integer���� �������Ϊ bigint������bigint�����������Ϊ numeric�� ����������Ľ���� double precision�� �������������������ͬ�� ��������ֵ�� expression ���ܺ�
variance(expression) smallint, integer, bigint, real, double precision, ���� numeric. ������������ double precision�� ������ numeric�� ���ֵ�IJ��������׼����ƫ���ƽ������

��ע����� count ���⣬ ��Щ������û��ѡ����ʱ���� NULL�� ����Ҫָ�����Ƕ��������н��� sum ������ NULL�� ����������Ԥ�ڵ��㡣 ��Ҫʱ������ coalesce �� NULL �滻���㡣

ע��: �����ۼ� bool_and �� bool_or ��Ӧ��׼�� SQL �ۼ� every �� any ���� some������ any �� some�� ��׼�﷨�����ƺ���Щ���õ����壺

SELECT b1 = ANY((SELECT b2 FROM t2 ...)) FROM t1 ...;

����� ANY �ȿ��Ա���Ϊ������һ���Ӳ�ѯ��Ҳ������Ϊ��һ���ۼ��������ѯ���ʽ���� 1 �е绰���� ��˱�׼�������޷�������Щ�ۼ���

ע��: ϰ����ʹ������ RDBMS ��Ʒ���û����ܻ�� PostgreSQL �����һЩ�ۼ������������ص�е���֣��ر��Ƕ���������оۼ���ʱ�� �����仰˵�������� WHERE �Ӿ��ʱ�򣩡� ���磬һ�����������IJ�ѯ��

SELECT min(col) from sometable;

���ᱻ PostgreSQL �Զ����������˳��ɨ�����ʽ����ִ�С� ���������ݿ�ϵͳ���ܻ�������IJ�ѯ�Ż���ʹ��ij���ֶ��ϵ������ķ�ʽ������������Ļ����� �� PostgreSQL �����ƵĻ��У� �������������д���Ļ����ۼ����� max() �� count() ����Ҫ��һ��˳��ɨ�衣

PostgreSQL �޷������׵�ʵ�������� �Ż�����Ϊ���������û�����ľۼ���ѯ����Ϊ min()�� max()���� count() ����ʹ��һ���ۼ���������ͨ API ����ģ������ijЩ����� ��Щ������ִ�в�����Ҫ�涨"����ת��"��

���˵��ǣ����� min() �� max()�� ������Щ�򵥵ķ������ƿ�������������ʾ�IJ�ѯ�͵�Ч������IJ�ѯ�� ���ǣ������Ŀ���ֶ�������������ô����������һ�� B+ ���������Ż���

SELECT col from sometable ORDER BY col ASC LIMIT 1;

���ƵIJ�ѯ��ͨ���������ѯ�� ASC �滻�� DESC �����ˣ�Ҳ�������� max() �ĵط���

�����ǣ��ڶ�ȫ�������ʱ��û�����Ƽ򵥵IJ�ѯ�������ڸĽ� count() �����ܡ�