Ðàçðàáîòêà áàç äàííûõ â Delphi. 11 Óðîêîâ


 Îïåðàöèè ñðàâíåíèÿ


Ðàññìîòðèì îïåðàöèè ñðàâíåíèÿ. Ðåëÿöèîííûå îïåðàòîðû ìîãóò èñïîëüçîâàòüñÿ ñ ðàçëè÷íûìè ýëåìåíòàìè. Ïðè ýòîì âàæíî ñîáëþäàòü ñëåäóþùåå ïðàâèëî: ýëåìåíòû äîëæíû èìåòü ñðàâíèìûå òèïû. Åñëè â áàçå äàííûõ îïðåäåëåíû äîìåíû, òî ñðàâíèâàåìûå ýëåìåíòû äîëæíû îòíîñèòüñÿ ê îäíîìó äîìåíó.

×òî æå ìîæåò áûòü ýëåìåíòîì ñðàâíåíèÿ? Ýëåìåíòîì ñðàâíåíèÿ ìîæåò âûñòóïàòü:

·     çíà÷åíèå ïîëÿ

·     ëèòåðàë

·     àðèôìåòè÷åñêîå âûðàæåíèå

·     àãðåãèðóþùàÿ ôóíêöèÿ

·     äðóãàÿ âñòðîåííàÿ ôóíêöèÿ

·     çíà÷åíèå (çíà÷åíèÿ), âîçâðàùàåìûå ïîäçàïðîñîì.

Ïðè ñðàâíåíèè ëèòåðàëîâ êîíå÷íûå ïðîáåëû èãíîðèðóþòñÿ. Òàê, ïðåäëîæåíèå WHERE first_name = ‘Ïåòð    ‘ áóäåò èìåòü òîò æå ðåçóëüòàò, ÷òî è ïðåäëîæåíèå WHERE first_name = ‘Ïåòð’.

SELECT first_name, last_name, dept_no

FROM employee

WHERE job_code = "Admin"   ïîëó÷èòü ñïèñîê  ñîòðóäíèêîâ
                                                                         (è íîìåðà èõ îòäåëîâ),


                                                                         çàíèìàþùèõ äîëæíîñòü
                                                                         àäìèíèñòðàòîðîâ

FIRST_NAME      LAST_NAME            DEPT_NO

=============== ==================== =======

Terri           Lee                  000     

Ann             Bennet               120    

Sue Anne        O'Brien              670    

Kelly           Brown                600

SELECT first_name, last_name, dept_no,

       job_country

FROM employee

WHERE job_country <> "USA" ïîëó÷èòü ñïèñîê  ñîòðóäíèêîâ
                                                                            (à òàêæå íîìåðà èõ îòäåëîâ
                                                                            è ñòðàíó),
                                                                            ðàáîòàþùèõ âíå ÑØÀ

FIRST_NAME      LAST_NAME        DEPT_NO JOB_COUNTRY

=============== ================ ======= ==============

Ann             Bennet           120     England

Roger           Reeves           120     England

Willie          Stansbury        120     England

Claudia         Sutherland       140     Canada

Yuki            Ichida           115     Japan

Takashi         Yamamoto         115     Japan

Roberto         Ferrari          125     Italy

Jacques         Glon             123     France

Pierre          Osborne          121     Switzerland



Ñîäåðæàíèå ðàçäåëà