Professional Documents
Culture Documents
--
-- SQL 02: Jonctiuni interne
--
-- ultima actualizare: 2020-03-07
-- JOIN
-- ############################################################################
-- Care sunt albumele formatiei `U2`
-- ############################################################################
-- sol. 2 - ECHI-JOIN
select *
from album inner join artist on album.artistid = artist.artistid
where name = 'U2'
--
select album.*, artist.name
from album inner join artist on album.artistid = artist.artistid
where name = 'U2'
-- ############################################################################
-- Care sunt piesele de pe albumul `Achtung Baby` al formatiei U2?
-- ############################################################################
-- ############################################################################
-- Care sunt piesele formatiei `Led Zeppelin` compuse de cel putin trei muzicieni?
-- ############################################################################
SELECT track.*
FROM track
INNER JOIN album ON track.albumid = album.albumid
INNER JOIN artist ON album.artistid = artist.artistid
WHERE artist.name = 'Led Zeppelin' AND
(UPPER(composer) LIKE '%LED ZEPPELIN%'
OR
regexp_match(composer, '.*(/|,).*(/|,).*') IS NOT NULL )
-- ############################################################################
-- Care sunt piesele formatiei U2 vandute in anul 2013?
-- ############################################################################
-- ############################################################################
-- AUTOJONCTIUNE
-- ############################################################################
-- ############################################################################
-- Care sunt celelalte albume ale formatiei care a lansat
-- albumul 'Achtung Baby'?
-- ############################################################################
-- ############################################################################
-- Care sunt celelalte piese de pe albumul pe care apare piesa
-- 'For Those About To Rock (We Salute You)'?
-- ############################################################################
-- sau
select customer2.*
from customer customer1
inner join customer customer2 on customer1.country = customer2.country
where customer1.firstname = 'Robert' and customer1.lastname = 'Brown'
-- ############################################################################
-- Care este numele angajatului: lastname = 'Johnson' AND firstname = 'Steve'
-- ############################################################################
-- ############################################################################
-- Probleme de rezolvat la curs/laborator/acasa
-- ############################################################################
-- Care sunt piesele formatiei `Led Zeppelin` la care, printre compozitori, nu apare
-- `Robert Plant`
-- Care sunt piesele formatiei `Led Zeppelin` la care, printre compozitori, nu apare
-- nici `Robert Plant`, nici `Jimmy Page`
-- ############################################################################
-- La ce intrebari raspund urmatoarele interogari ?
-- ############################################################################
--
SELECT track.*
FROM track
INNER JOIN album ON track.albumid = album.albumid
INNER JOIN artist ON album.artistid = artist.artistid
WHERE artist.name = 'Led Zeppelin' AND
(UPPER(composer) LIKE '%BONHAM%' OR UPPER(composer) LIKE '%LED ZEPPELIN%')
--
select name as artist_name, title as album_title
from artist inner join album on artist.artistid = album.artistid
where name = title
order by 1 ;
--
select track.name as track_name,
title as album_title, artist.name as artist_name,
milliseconds / 1000 as duration_seconds
from track
inner join album on track.albumid = album.albumid
inner join artist on album.artistid = artist.artistid
where artist.name = 'U2'
order by milliseconds desc
limit 9