PostgreSQL

Скачать в pdf «PostgreSQL»


test=> SELECT firstname, test->    state,


test->    CASE


when


state =


‘PA’


then ‘close’


when


state =


‘NJ’


OR state = ‘MD’ THEN ‘far

test->    ELSE ‘very far’


test->    END AS distance


test-> FROM friend test-> ORDER BY firstname;


firstname


| state


|


distance


Dean


| ma


|


very far


Dick


| NJ


|


far


Ned


| MD


|


far


Sandy


| NJ


|


far


Sandy


| MA


|


very far


Victor


| PA


|


close

(6 rows)


Figure 4.20: Complex case example


test=> SELECT state FROM friend ORDER BY state; state


MA


MA


MD


nj


nj


pa


(6 rows)


test=> SELECT DISTINCT state FROM friend ORDER BY state; state


MA


MD


NJ


pa


(4 rows)


test=> SELECT DISTINCT city, state FROM friend ORDER BY state, city;


city


| state


Boston


| MA


Plymouth


| MA


Cedar Creek


| MD


Ocean City


| NJ


Williamsport


| PA

(5 rows)


Figure 4.21: Distinct prevents duplicates


Function


Set option


DATESTYLE


DATESTYLE TO ’ISO’ | ’POSTGRES’ | ’SQF | ’US’ |


’NonEuropean’ 1 ’European’ | ’German’

Скачать в pdf «PostgreSQL»