jaagup@praktika1 ~ $ mysql -umart -pajutine1234 mart filmivaatajad epost,sugu,synniaasta CREATE TABLE dh_jaagup_filmivaatajad( epost VARCHAR(50) NOT NULL PRIMARY KEY, sugu ENUM('M','N'), synniaasta INT ); INSERT INTO dh_jaagup_filmivaatajad VALUES ('juku@eesti.ee', 'M', 2008); INSERT INTO dh_jaagup_filmivaatajad VALUES ('kati@eesti.ee', 'N', 2009); INSERT INTO dh_jaagup_filmivaatajad VALUES ('mati@eesti.ee', 'M', 2008); INSERT INTO dh_jaagup_filmivaatajad VALUES ('madis@eesti.ee', 'M', 2007); INSERT INTO dh_jaagup_filmivaatajad VALUES ('mari@eesti.ee', 'N', 2008); INSERT INTO dh_jaagup_filmivaatajad VALUES ('marju@eesti.ee', 'N', 2009); SELECT * FROM dh_jaagup_filmivaatajad; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | juku@eesti.ee | M | 2008 | | kati@eesti.ee | N | 2009 | | madis@eesti.ee | M | 2007 | | mari@eesti.ee | N | 2008 | | marju@eesti.ee | N | 2009 | | mati@eesti.ee | M | 2008 | +----------------+------+------------+ 6 rows in set (0.00 sec) SELECT * FROM dh_jaagup_filmivaatajad ORDER BY synniaasta; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | madis@eesti.ee | M | 2007 | | juku@eesti.ee | M | 2008 | | mari@eesti.ee | N | 2008 | | mati@eesti.ee | M | 2008 | | kati@eesti.ee | N | 2009 | | marju@eesti.ee | N | 2009 | +----------------+------+------------+ SELECT * FROM dh_jaagup_filmivaatajad ORDER BY synniaasta DESC; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | kati@eesti.ee | N | 2009 | | marju@eesti.ee | N | 2009 | | juku@eesti.ee | M | 2008 | | mari@eesti.ee | N | 2008 | | mati@eesti.ee | M | 2008 | | madis@eesti.ee | M | 2007 | +----------------+------+------------+ SELECT * FROM dh_jaagup_filmivaatajad ORDER BY synniaasta DESC LIMIT 3; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | kati@eesti.ee | N | 2009 | | marju@eesti.ee | N | 2009 | | juku@eesti.ee | M | 2008 | +----------------+------+------------+ SELECT * FROM dh_jaagup_filmivaatajad WHERE sugu='N'; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | kati@eesti.ee | N | 2009 | | mari@eesti.ee | N | 2008 | | marju@eesti.ee | N | 2009 | +----------------+------+------------+ SELECT * FROM dh_jaagup_filmivaatajad WHERE sugu='N' ORDER BY synniaasta; +----------------+------+------------+ | epost | sugu | synniaasta | +----------------+------+------------+ | mari@eesti.ee | N | 2008 | | kati@eesti.ee | N | 2009 | | marju@eesti.ee | N | 2009 | +----------------+------+------------+ SELECT COUNT(*) FROM dh_jaagup_filmivaatajad; +----------+ | COUNT(*) | +----------+ | 6 | +----------+ -- Lugege COUNT(*) abil kokku, mitu tüdrukut on SELECT COUNT(*) FROM dh_jaagup_filmivaatajad WHERE sugu='N'; +----------+ | COUNT(*) | +----------+ | 3 | +----------+ SELECT epost, 2017-synniaasta FROM dh_jaagup_filmivaatajad WHERE sugu='N'; +----------------+-----------------+ | epost | 2017-synniaasta | +----------------+-----------------+ | kati@eesti.ee | 8 | | mari@eesti.ee | 9 | | marju@eesti.ee | 8 | +----------------+-----------------+ SELECT sugu, COUNT(*) FROM dh_jaagup_filmivaatajad GROUP BY sugu; +------+----------+ | sugu | COUNT(*) | +------+----------+ | M | 3 | | N | 3 | +------+----------+ Looge juurde tabel dh_jaagup_filmivaatamised tulpadega id, epost, filminimi, aasta Täitke andmetega Küsige mõned väärtused CREATE TABLE dh_jaagup_filmivaatamised( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, epost VARCHAR(50), filminimi VARCHAR(255), aasta INT, FOREIGN KEY(epost) REFERENCES dh_jaagup_filmivaatajad(epost) ); INSERT INTO dh_jaagup_filmivaatamised VALUES (DEFAULT, 'juku@eesti.ee', 'Kevade', 2016); INSERT INTO dh_jaagup_filmivaatamised VALUES (DEFAULT, 'juku@eesti.ee', 'Kevade', 2017); INSERT INTO dh_jaagup_filmivaatamised VALUES (DEFAULT, 'kati@eesti.ee', 'Kevade', 2016); INSERT INTO dh_jaagup_filmivaatamised VALUES (DEFAULT, 'kati@eesti.ee', 'Suvi', 2017); INSERT INTO dh_jaagup_filmivaatamised VALUES (DEFAULT, 'mari@eesti.ee', 'Kevade', 2017); MariaDB [mart]> SELECT * FROM dh_jaagup_filmivaatamised; +----+---------------+-----------+-------+ | id | epost | filminimi | aasta | +----+---------------+-----------+-------+ | 1 | juku@eesti.ee | Kevade | 2016 | | 2 | juku@eesti.ee | Kevade | 2017 | | 3 | kati@eesti.ee | Kevade | 2016 | | 4 | kati@eesti.ee | Suvi | 2017 | | 6 | mari@eesti.ee | Kevade | 2017 | +----+---------------+-----------+-------+ SELECT * FROM dh_jaagup_filmivaatamised INNER JOIN dh_jaagup_filmivaatajad ON dh_jaagup_filmivaatamised.epost=dh_jaagup_filmivaatajad.epost; +----+---------------+-----------+-------+---------------+------+------------+ | id | epost | filminimi | aasta | epost | sugu | synniaasta | +----+---------------+-----------+-------+---------------+------+------------+ | 1 | juku@eesti.ee | Kevade | 2016 | juku@eesti.ee | M | 2008 | | 2 | juku@eesti.ee | Kevade | 2017 | juku@eesti.ee | M | 2008 | | 3 | kati@eesti.ee | Kevade | 2016 | kati@eesti.ee | N | 2009 | | 4 | kati@eesti.ee | Suvi | 2017 | kati@eesti.ee | N | 2009 | | 6 | mari@eesti.ee | Kevade | 2017 | mari@eesti.ee | N | 2008 | +----+---------------+-----------+-------+---------------+------+------------+ SELECT filminimi, sugu FROM dh_jaagup_filmivaatamised INNER JOIN dh_jaagup_filmivaatajad ON dh_jaagup_filmivaatamised.epost=dh_jaagup_filmivaatajad.epost; +-----------+------+ | filminimi | sugu | +-----------+------+ | Kevade | M | | Kevade | M | | Kevade | N | | Suvi | N | | Kevade | N | +-----------+------+ -- Ilma Joinita kuvage, mitu korda millist filmi vaadati SELECT filminimi, COUNT(*) FROM dh_jaagup_filmivaatamised GROUP BY filminimi; +-----------+----------+ | filminimi | COUNT(*) | +-----------+----------+ | Kevade | 4 | | Suvi | 1 | +-----------+----------+ SELECT filminimi, COUNT(*) AS kogus FROM dh_jaagup_filmivaatamised GROUP BY filminimi; +-----------+-------+ | filminimi | kogus | +-----------+-------+ | Kevade | 4 | | Suvi | 1 | +-----------+-------+ SELECT filminimi, sugu, COUNT(*) FROM dh_jaagup_filmivaatamised INNER JOIN dh_jaagup_filmivaatajad ON dh_jaagup_filmivaatamised.epost=dh_jaagup_filmivaatajad.epost GROUP BY filminimi, sugu; +-----------+------+----------+ | filminimi | sugu | COUNT(*) | +-----------+------+----------+ | Kevade | M | 2 | | Kevade | N | 2 | | Suvi | N | 1 | +-----------+------+----------+ http://praktika1.cs.tlu.ee/phpmyadmin SELECT production_year FROM efis_film; SELECT production_year, COUNT(*) FROM efis_film GROUP BY production_year; +-----------------+----------+ | production_year | COUNT(*) | +-----------------+----------+ | | 888 | | 1944 | 1 | | 2010 | 1 | | 1911 | 2 | | 1912 | 4 | | 1913 | 8 | | 1914 | 3 | | 1915 | 1 | | 1917 | 2 | | 1919 | 6 | | 1921 | 3 | | 1923 | 16 | | 1924 | 31 | | 1925 | 11 | | 1926 | 29 | | 1927 | 10 | | 1928 | 14 | | 1929 | 16 | | 1930 | 14 | | 1931 | 33 | | 1932 | 14 | | 1933 | 7 | | 1934 | 18 | | 1935 | 94 | | 1936 | 163 | | 1937 | 308 | | 1938 | 189 | | 1939 | 163 | | 1940 | 149 | | 1941 | 116 | | 1942 | 1 | | 1943 | 1 | | 1944 | 34 | | 1945 | 77 | | 1946 | 84 | | 1947 | 142 | | 1948 | 174 | | 1949 | 193 | | 1950 | 177 | | 1951 | 173 | | 1952 | 156 | | 1953 | 157 | | 1954 | 178 | | 1955 | 199 | | 1956 | 263 | | 1957 | 278 | | 1958 | 298 | | 1959 | 341 | | 1960 | 376 | | 1961 | 306 | | 1962 | 323 | | 1963 | 335 | | 1964 | 347 | | 1965 | 326 | | 1966 | 255 | | 1967 | 268 | | 1968 | 261 | | 1969 | 261 | | 1970 | 314 | | 1971 | 291 | | 1972 | 280 | | 1973 | 294 | | 1974 | 246 | | 1975 | 261 | | 1976 | 249 | | 1977 | 228 | | 1978 | 288 | | 1979 | 294 | | 1980 | 352 | | 1981 | 273 | | 1982 | 279 | | 1983 | 318 | | 1984 | 368 | | 1985 | 278 | | 1986 | 279 | | 1987 | 307 | | 1988 | 351 | | 1989 | 318 | | 1990 | 204 | | 1991 | 137 | | 1992 | 128 | | 1993 | 119 | | 1994 | 94 | | 1995 | 84 | | 1996 | 97 | | 1997 | 112 | | 1998 | 96 | | 1999 | 84 | | 2000 | 103 | | 2001 | 120 | | 2002 | 113 | | 2003 | 148 | | 2004 | 138 | | 2005 | 151 | | 2006 | 143 | | 2007 | 170 | | 2008 | 192 | | 2009 | 223 | | 2010 | 183 | | 2011 | 216 | | 2012 | 149 | | 2013 | 139 | | 2014 | 160 | | 2015 | 170 | | 2016 | 109 | | 2017 | 97 | | 2018 | 2 | | 2019 | 3 | +-----------------+----------+ SELECT production_year, COUNT(*) AS kogus FROM efis_film GROUP BY production_year ORDER BY kogus DESC LIMIT 10; +-----------------+-------+ | production_year | kogus | +-----------------+-------+ | | 888 | | 1960 | 376 | | 1984 | 368 | | 1980 | 352 | | 1988 | 351 | | 1964 | 347 | | 1959 | 341 | | 1963 | 335 | | 1965 | 326 | | 1962 | 323 | +-----------------+-------+ Tehke samasugune päring tulba archive_fond_name põhjal Millises fondis kui mitu filmi SELECT archive_fond_name, COUNT(*) AS kogus FROM efis_film GROUP BY archive_fond_name ORDER BY kogus DESC LIMIT 10; +------------------------------------------------------------+-------+ | archive_fond_name | kogus | +------------------------------------------------------------+-------+ | Tallinnfilm AS | 8668 | | | 4601 | | Filmistuudio Eesti Kultuurfilm | 948 | | Filmistuudio Eesti Reklaamfilm | 790 | | Eesti Televisioon | 348 | | Tartu Ülikool | 214 | | Tallinna Puhkeparkide Direktsiooni Filmiamatööride Klubi | 202 | | Tallinnfilm | 173 | | Filmistuudio Eesti Telefilm | 136 | | Eesti Filmiamatööride Liit | 131 | +------------------------------------------------------------+-------+ Näidake 10 levinumat fondi enne 1980 aastat tehtud filmide hulgas SELECT archive_fond_name, COUNT(*) AS kogus FROM efis_film WHERE production_year<1980 GROUP BY archive_fond_name ORDER BY kogus DESC LIMIT 10; Näidake 10 levinumat fondi pärast 1980 aastat tehtud filmide hulgas SELECT archive_fond_name, COUNT(*) AS kogus FROM efis_film WHERE production_year<1980 AND archive_fond_name LIKE '%tallinnfilm%' GROUP BY archive_fond_name ORDER BY kogus DESC LIMIT 10; +-------------------+-------+ | archive_fond_name | kogus | +-------------------+-------+ | Tallinnfilm AS | 6874 | | Tallinnfilm | 84 | | Tallinnfilmi AS | 9 | +-------------------+-------+ SELECT archive_fond_name, COUNT(*) AS kogus FROM efis_film WHERE archive_fond_name RLIKE 'Tal[l]?in[n]?film' GROUP BY archive_fond_name ORDER BY kogus DESC LIMIT 10; +-------------------+-------+ | archive_fond_name | kogus | +-------------------+-------+ | Tallinnfilm AS | 8668 | | Tallinnfilm | 173 | | Tallinnfilmi AS | 12 | | AS Tallinnfilm | 1 | | Talinnfilm AS | 1 | | Tallinfilm AS | 1 | +-------------------+-------+ SHOW TABLES; +------------------------------------+ | Tables_in_mart | +------------------------------------+ | dh_anastasia_filmivaatajad | | dh_anastasia_filmivaatamised | | dh_anastasia_filmivaatamised1 | | dh_anastasia_filmivaatamised2 | | dh_annika_filmivaatajad | | dh_annika_filmivaatamised | | dh_astrid_filmivaatajad | | dh_astrid_filmivaatamised | | dh_hagi_filmivaatajad | | dh_hagi_filmivaatamised | | dh_jaagup_filmivaatajad | | dh_jaagup_filmivaatamised | | dh_kaisa_filmivaatajad | | dh_kaisa_filmivaatamised | | dh_katarina_filmivaatajad | | dh_katarina_filmivaatamised | | dh_kristina_filmivaatajad | | dh_kristina_filmivaatamised | | dh_liisi_filmivaatajad | | dh_liisi_filmivaatamised | | efis_company | | efis_company_description | | efis_company_image | | efis_email_templates | | efis_festival | | efis_festival_translation | | efis_film | | efis_film_archive_location | | efis_film_change_log | | efis_film_copyright | | efis_film_country | | efis_film_distributor | | efis_film_edition | | efis_film_festival | | efis_film_gallery | | efis_film_gallery_file | | efis_film_gallery_file_translation | | efis_film_gallery_translation | | efis_film_keyword | | efis_film_maker | | efis_film_media_publication | | efis_film_media_publication_file | | efis_film_music | | efis_film_music_maker | | efis_film_physical_description | | efis_film_production | | efis_film_purchase | | efis_film_quote | | efis_film_relation | | efis_film_role_person | | efis_film_scenario_file | | efis_film_screening | | efis_film_screening_result | | efis_film_section | | efis_film_seq | | efis_film_sound_clip | | efis_film_title_episode | | efis_film_title_parallel | | efis_film_track | | efis_film_translation | | efis_film_type | | efis_film_type_rel | | efis_film_type_rel_veebist | | efis_film_type_translation | | efis_film_video | | efis_keyword | | efis_keyword_group | | efis_keyword_group_translation | | efis_keyword_keyword_group | | efis_keyword_translation | | efis_message_receivers | | efis_message_thread_receivers | | efis_message_threads | | efis_messages | | efis_messages_rel} | | efis_people | | efis_people_description | | efis_people_image | | efis_people_image_translation | | efis_task | | efis_task_file | | efis_task_person | +------------------------------------+ EXPLAIN efis_film_translation; +------------------------------+------------------+------+-----+---------+------ ----------+ | Field | Type | Null | Key | Default | Extra | +------------------------------+------------------+------+-----+---------+------ ----------+ | id | int(11) unsigned | NO | PRI | NULL | auto_ increment | | film_id | int(11) unsigned | NO | MUL | NULL | | | language | varchar(5) | NO | | NULL | | | title_proper | varchar(255) | YES | | NULL | | | title_alternative | varchar(255) | YES | | NULL | | | title_avant | varchar(255) | YES | | NULL | | | title_working | varchar(255) | YES | | NULL | | | title_serial | varchar(255) | YES | | NULL | | | title_additional_info | varchar(255) | YES | | NULL | | | era_time | varchar(255) | YES | | NULL | | | content_summary | text | YES | | NULL | | | contents | text | YES | | NULL | | | scenario | text | YES | | NULL | | | bibliography | text | YES | | NULL | | | makers_remembrance | text | YES | | NULL | | | film_makers_full_list | text | YES | | NULL | | | general_material_designation | varchar(255) | YES | | NULL | | | indoor_shooting | text | NO | | NULL | | | outdoor_shooting | text | NO | | NULL | | | trivia | text | NO | | NULL | | | tagline | varchar(255) | NO | | NULL | | | short_introduction | text | NO | | NULL | | | synopsis | text | NO | | NULL | | | buyers_info | text | YES | | NULL | | | consumer_carrier | text | YES | | NULL | | | updated | datetime | NO | | NULL | | | updated_by | int(11) unsigned | NO | | NULL | | | created | datetime | NO | | NULL | | | created_by | int(11) unsigned | NO | | NULL | | +------------------------------+------------------+------+-----+---------+------ ----------+ MariaDB [mart]> EXPLAIN efis_film; +------------------------------+---------------------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------------------------+---------------------------------+------+-----+---------+----------------+ | id | int(11) unsigned | NO | PRI | NULL | auto_increment | | film_seq_id | int(11) unsigned | NO | MUL | NULL | | | film_version_number | int(11) unsigned | NO | | NULL | | | production_year | varchar(50) | NO | | NULL | | | profile_image_filename | varchar(255) | YES | | NULL | | | copyright_type | int(11) unsigned | NO | | NULL | | | copyright_register_info | varchar(255) | NO | | NULL | | | copyright_note_on_movie | varchar(255) | NO | | NULL | | | archive_standard_number | varchar(50) | NO | | NULL | | | archive_kriimsilm_id | varchar(50) | NO | | NULL | | | archive_movie_archive_url | varchar(255) | YES | | NULL | | | archive_err_url | varchar(255) | YES | | NULL | | | archive_arrival_date | varchar(255) | YES | | NULL | | | archive_handover_person_name | varchar(50) | NO | | NULL | | | archive_fond_name | varchar(100) | NO | | NULL | | | archive_fond_nr | varchar(25) | NO | | NULL | | | archive_archival_document_nr | varchar(25) | NO | | NULL | | | archive_usage_copy | varchar(50) | NO | | NULL | | | archive_usage_format | varchar(50) | NO | | NULL | | | archive_usage_start_date | varchar(50) | NO | | NULL | | | archive_usage_end_date | varchar(50) | NO | | NULL | | | archive_access_restriction | varchar(200) | NO | | NULL | | | archive_additional_material | text | NO | | NULL | | | record_info | text | NO | | NULL | | | record_sources | text | NO | | NULL | | | record_creator_opinion | text | NO | | NULL | | | efa_editor_opinion | text | NO | | NULL | | | efa_editor_status | varchar(50) | NO | | NULL | | | is_latest | tinyint(1) | NO | | NULL | | | is_visible | tinyint(1) | NO | | 1 | | | status_by | int(11) unsigned | NO | | NULL | | | status | enum('active','new','archived') | NO | | NULL | | | status_datetime | datetime | NO | | NULL | | | updated | datetime | NO | | NULL | | | updated_by | int(11) unsigned | NO | | NULL | | | created | datetime | NO | | NULL | | | created_by | int(11) unsigned | NO | | NULL | | +------------------------------+---------------------------------+------+-----+---------+----------------+ -- järjestage nimedega filmid alates uuemast SELECT title_proper, production_year FROM efis_film_translation INNER JOIN efis_film ON efis_film_translation.film_id=efis_film.id LIMIT 25; +----------------------------------+-----------------+ | title_proper | production_year | +----------------------------------+-----------------+ | 03:07 | 2001 | | 03:07 | 2001 | | Vanapagan | 2006 | | 10 minutit võitleva ateistiga | 1976 | | 30 minutit vaikust | 2004 | | 30 Minutes of Silence | 2004 | | 31. osakonna hukk I jagu | 1979 | | Murder on the 31st Floor Part I | 1979 | | 31. osakonna hukk II jagu | 1980 | | Murder on the 31st Floor Part II | 1980 | | Aaria | 1997 | | Aria | 1997 | | Aednik | 2001 | | The Gardner | 2001 | | Aeg elada, aeg armastada | 1976 | | Time to Live, Time to Love | 1976 | | Aeg maha! | 1975 | | Agent Sinikael | 2002 | | Agent Wild Duck | 2002 | | Agu Sihvka annab aru | 1970 | | Sellised kolm lugu: Aida | 1999 | | Amatöörid | 2008 | | Amateurs | 2008 | | Ameerika mäed | 1994 | | American Mountains | 1994 | +----------------------------------+-----------------+ SELECT title_proper, production_year, efis_film.id, GROUP_CONCAT(language) FROM efis_film_translation INNER JOIN efis_film ON efis_film_translation.film_id=efis_film.id GROUP BY efis_film.id LIMIT 25; +--------------------------------+-----------------+----+------------------------+ | title_proper | production_year | id | GROUP_CONCAT(language) | +--------------------------------+-----------------+----+------------------------+ | 03:07 | 2001 | 1 | et,en | | Vanapagan | 2006 | 2 | et | | 10 minutit võitleva ateistiga | 1976 | 5 | et | | 30 minutit vaikust | 2004 | 7 | et,en | | 31. osakonna hukk I jagu | 1979 | 8 | et,en | | 31. osakonna hukk II jagu | 1980 | 9 | et,en | | Aaria | 1997 | 12 | et,en | | Aednik | 2001 | 13 | et,en | | Aeg elada, aeg armastada | 1976 | 14 | et,en | | Aeg maha! | 1975 | 15 | et | | Agent Sinikael | 2002 | 16 | et,en | | Agu Sihvka annab aru | 1970 | 17 | et | | Sellised kolm lugu: Aida | 1999 | 19 | et | | Amatöörid | 2008 | 23 | et,en | | Ameerika mäed | 1994 | 24 | et,en | | Andruse õnn | 1955 | 25 | et,en | | Ankur | 1991 | 26 | et | | Armas tuss 50 aastat hiljem | 2000 | 30 | et | | Armastuse lahinguväljad | 1992 | 31 | et,en | | Armastuse pisielukas | 1921 | 32 | et | | Armastusest hoolimata | 2008 | 33 | et | | Armatsoonid | 1996 | 34 | et | | Armuavaldus | 1995 | 35 | et | | Armuke | 1999 | 36 | et | | Aruanne | 1997 | 38 | et,en | +--------------------------------+-----------------+----+------------------------+