1 / 29

SQL: korelisani podupit

SQL: korelisani podupit. SELECT I.NAZIV FROM I WHERE ‘k3’ IN (SELECT KI.K_SIF FROM KI WHERE KI.I_SIF = I.I_SIF). SQL: korelisani podupit nad jednom tabelom. Šifre svih knjiga koje izdaje više od jednog izdavača: SELECT DISTINCT KIX.K _ SIF FROM KI KIX WHERE KIX.K _ SIF IN

kurt
Download Presentation

SQL: korelisani podupit

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL: korelisani podupit SELECT I.NAZIV FROM I WHERE ‘k3’ IN (SELECT KI.K_SIF FROM KI WHERE KI.I_SIF = I.I_SIF)

  2. SQL: korelisani podupit nad jednom tabelom Šifre svih knjiga koje izdaje više od jednog izdavača: SELECT DISTINCT KIX.K_SIF FROM KI KIX WHERE KIX.K_SIF IN (SELECT KIY.K_SIF FROM KIKIY WHERE KIY.I_SIF <> KIX.I_SIF)

  3. SQL: podupiti- egzistencijalni kvantor SELECT I.NAZIV FROM I WHERE EXISTS (SELECT * FROM KI WHERE KI.I_SIF = I.I_SIF AND KI.K_SIF = ‘k3’)

  4. SQL: podupiti- univerzalni kvantor • Naći nazive izdavača koji izdaju sve knjige Branka Ćopića

  5. SQL: podupiti- univerzalni kvantor • Nazivi knjiga Branka Ćopića:

  6. SQL: podupiti- univerzalni kvantor • Nazivi izdavača koji su izdali sve knjige B.Ć.

  7. SQL: skalarne funkcije • Konverzione, npr. DECIMAL(), DIGITS(), FLOAT(), INTEGER() • Opšte, npr. LENGTH() – dužina podataka u bajtovima • Aritmetičke, npr. ABS(), TAN(), SQRT(),TRUNC() • Obrada znakovnih podataka: SUBSTR(), POSSTR() • Nad specifičnim tipovima, npr. TIME(), YEAR(), DATE(), DAY() nad tipovima TIME, DATE, TIMESTAMP

  8. SQL: skalarne funkcije, CASE-WHEN • SELECT NAZIV, CASE SUBSTR(DRZAVA,1,1) WHEN 'J' THEN 'Yugoslavia' WHEN 'A' THEN 'USA' WHEN 'E' THEN 'UK' END AS DRZAVA_ENG FROM I

  9. SQL: agregatne funkcije • COUNT • SUM • AVG • MAX • MIN • -------------------------------------- • STD(expr) • STDDEV(expr) • VARIANCE(expr)

  10. SQL: agregatne funkcije - count SELECT COUNT (DISTINCT I_SIF) FROM KI (rezultat?) SELECT COUNT(*) FROM KI WHERE KI.K_SIF = ‘k6’ (rezultat?)

  11. Tabele KI, I

  12. SQL: agregatne funkcije – sum, max SELECT SUM(TIRAZ) FROM KI WHERE KI.K_SIF = ‘k6’ • (rezultat?) Agregatna funkcija u where liniji??? SELECT I.I_SIF FROM I WHERE STATUS < (SELECT MAX(STATUS) FROM I) • (rezultat?)

  13. SQL: agregatne funkcije – avg SELECT IX.I_SIF, IX.STATUS, IX.DRZAVA FROM I IX WHERE IX.STATUS >= (SELECT AVG(STATUS) FROM I IY WHERE IY.DRZAVA = IX.DRZAVA)

  14. SQL: agregatne funkcije – avg - rezultat

  15. SQL: GROUP BY SELECT K_SIF, SUM(TIRAZ) FROM KI GROUP BY K_SIF

  16. SQL: HAVING SELECT K_SIF FROM KI GROUP BY K_SIF HAVING COUNT(*) > 1

  17. SQL: UNION, INTERSECT, EXCEPT SELECT K_SIF FROM K WHERE OBLAST = ‘roman’ UNION SELECT K_SIF FROM KI WHERE I_SIF = ‘i2’

  18. SQL: tabela K

  19. SQL: UNION, INTERSECT, EXCEPT SELECT DRZAVA FROM I INTERSECT SELECT DRZAVA FROM P

  20. SQL: tabela P

  21. SQL: UNION, INTERSECT, EXCEPT SELECT DRZAVA FROM I INTERSECT ALL SELECT DRZAVA FROM P

  22. SQL: UNION, INTERSECT, EXCEPT SELECT DRZAVA FROM P EXCEPT SELECT DRZAVA FROM I EXCEPT ALL???

  23. SQL: ORDER BY - 1 SELECT I_SIF, STATUS FROM I ORDER BY STATUS DESC

  24. SQL: ORDER BY - 2 SELECT K_SIF, I_SIF, IZDANJE, ‘Tiraz u hiljadama =’, TIRAZ/1000 FROM KI ORDER BY 5, I_SIF

  25. SQL: ORDER BY – 2- rezultat

  26. SQL: operator WITH • Iz tabele sa parovima (IME, NAZIV) koja sadrži imena pisaca i nazive izdavačakoji izdaju knjige tih pisaca, izdati nazive svih izdavača Branka Ćopića. • WITH PI AS (SELECT DISTINCT IME, NAZIV FROM P, I, KP, KI WHERE P.P SIF=KP.P SIF AND KP.K SIF=KI.K SIF AND KI.I SIF=I.I SIF) SELECT NAZIV FROM PI WHERE IME='B.Copic'

  27. SQL: operator WITH - rezultat

  28. SQL: Način izvršavanja SELECT iskaza SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... • Dekartov proizvod (FROM) • Restrikcija (WHERE) • Grupisanje (GROUP BY) • Izbor grupa (HAVING) • Projekcija (SELECT) • Uređenje (ORDER BY)

  29. SQL: relaciona kompletnost • 1. Unija, presek, razlika – direktno • 2. Dekartov proizvod: FROM • 3. Projekcija: SELECT • 4. Restrikcija: WHERE • 5. Spajanje: SELECT-FROM-WHERE • 6. deljenje: R(A;B) : S(C) SELECT A FROM R RX WHERE NOT EXISTS (SELECT * FROM S WHERE NOT EXISTS (SELECT * FROM R WHERE R.B = S.C AND R.A = RX.A))

More Related