PostgreSQL 8.0.0 �����ĵ���PostgreSQL �й� ������ | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 9. �����Ͳ����� | Fast Forward | Next |
�ۼ����� ��һ������ֵ�����һ������� Table 9-37 ��ʾ���ڽ��ۼ������� �ۼ�������������� Section 4.2.7����͡���ο� Part I ��ȡ���ӵĽ�������Ϣ��
Table 9-37. �ۼ�����
��ע����� 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() �����ܡ�