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

       

 Ñàìîñîåäèíåíèÿ


 íåêîòîðûõ çàäà÷àõ íåîáõîäèìî ïîëó÷èòü èíôîðìàöèþ, âûáðàííóþ îñîáûì îáðàçîì òîëüêî èç îäíîé òàáëèöû. Äëÿ ýòîãî èñïîëüçóþòñÿ òàê íàçûâàåìûå ñàìîñîåäèíåíèÿ, èëè ðåôëåêñèâíûå ñîåäèíåíèÿ. Ýòî íå îòäåëüíûé âèä ñîåäèíåíèÿ, à ïðîñòî ñîåäèíåíèå òàáëèöû ñ ñîáîé ñ ïîìîùüþ àëèàñîâ. Ñàìîñîåäèíåíèÿ ïîëåçíû â ñëó÷àÿõ, êîãäà íóæíî ïîëó÷èòü ïàðû àíàëîãè÷íûõ ýëåìåíòîâ èç îäíîé è òîé æå òàáëèöû.

SELECT one.last_name, two.last_name, 

       one.hire_date

FROM employee one, employee two

WHERE one.hire_date = two.hire_date

  AND one.emp_no < two.emp_no
                      ïîëó÷èòü ïàðû ôàìèëèé ñîòðóäíèêîâ,
                                                             êîòîðûå ïðèíÿòû íà ðàáîòó â îäèí
                                                             è òîò æå äåíü

LAST_NAME            LAST_NAME              HIRE_DATE

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

Nelson               Young                28-DEC-1988

Reeves               Stansbury            25-APR-1991



Bishop               MacDonald             1-JUN-1992

Brown                Ichida                4-FEB-1993

SELECT d1.department, d2.department, d1.budget

FROM department d1, department d2

WHERE d1.budget = d2.budget

  AND d1.dept_no < d2.dept_no
                                                             ïîëó÷èòü ñïèñîê ïàð îòäåëîâ ñ
                                                             îäèíàêîâûìè ãîäîâûìè áþäæåòàìè

DEPARTMENT                DEPARTMENT                   BUDGET

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

Software Development      Finance                   400000.00

Field Office: East Coast  Field Office: Canada      500000.00

Field Office: Japan       Field Office: East Coast  500000.00

Field Office: Japan       Field Office: Canada      500000.00

Field Office: Japan       Field Office: Switzerland 500000.00

Field Office: Singapore   Quality Assurance         300000.00

Field Office: Switzerland Field Office: East Coast  500000.00



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