0% found this document useful (0 votes)
117 views

SQL Exercise

The document contains SQL statements that create two tables, Locations and Events, insert data into the tables, and perform various queries on the tables. The Locations table stores information about event locations like name, address, capacity. The Events table stores information about specific events like name, date, cost. Several queries are written to select data from the tables based on various conditions on fields like location name, city, capacity, event cost, etc. and perform aggregation on the results.

Uploaded by

Ionescu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

SQL Exercise

The document contains SQL statements that create two tables, Locations and Events, insert data into the tables, and perform various queries on the tables. The Locations table stores information about event locations like name, address, capacity. The Events table stores information about specific events like name, date, cost. Several queries are written to select data from the tables based on various conditions on fields like location name, city, capacity, event cost, etc. and perform aggregation on the results.

Uploaded by

Ionescu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

create table Locations (

LocationID number constraint locations_pk primary key,

LocationName varchar2(100),

Address varchar2(100),

City varchar2(100),

Country varchar2(100) not null,

ContactPerson varchar2(100),

Capacity number,

Cost number

);

create table Events (

EventID number constraint events_pk primary key,

LocationID number,

EventName varchar2(100),

EventDate date,

EventCost number

);

Insert Into Locations Values (1, 'Parcul central', 'str. baritiu nr 84', 'Cluj-Napoca', 'Romania','Ana
Popescu',10000,0);

Insert Into Locations Values (2, 'Casa de Cultura', 'piata unirii', 'Cluj-Napoca', 'Romania','Dan
Cristian',300,1000);

Insert Into Locations Values (3, 'Piata Revolutiei', 'str. baritiu nr 84', 'Bucuresti', 'Romania','Cristina
Manole',10000,1000);

Insert Into Locations Values (4, 'Hugo Restaurant', 'str. 21 decembrie 1989', 'Cluj-Napoca',
'Romania','Crina Suciu',200,500);
Insert Into Locations Values (5, 'Piata Sfatului', 'str. statului nr 100', 'Brasov', 'Romania','Liana
Marinescu',600,600);

Insert Into Events Values (1, 1, 'Zilele Orasului Cluj', DATE '2017-05-05', 10000);

Insert Into Events Values (2, 1, 'Zilele Tineretului', DATE '2017-06-06', 1000);

Insert Into Events Values (3, 1, 'Marea Hamaceala', DATE '2017-07-07', 400);

Insert Into Events Values (4, 1, 'Zilele Folk', DATE '2017-05-09', 2000);

Insert Into Events Values (5, 2, 'Concert Andra', DATE '2017-07-05', 5000);

Insert Into Events Values (6, 2, 'Concert colinde', DATE '2017-12-06', 1500);

Insert Into Events Values (7, 3, 'Concert Revelion', DATE '2017-12-31', 20000);

Insert Into Events Values (8, 4, 'Eveniment testare', DATE '2017-05-07', 2000);

Insert Into Events Values (9, 4, 'Eveniment lansare revista', DATE '2017-09-07', 1000);

Insert Into Events Values (10, 5, 'Cerbul de aur', DATE '2017-09-07', 5000);

1.
a) Select* from Locations Where Capacity between 200 and 1000;

b) Select* from Locations Where LocationName Like '%a%';

c) Select* from Locations Where Not City='Cluj-Napoca';

d) Select* From Locations Where (Cost='0' or Cost='500' or Cost='600') AND (City='Brasov' or City='Cluj-
Napoca') And Capacity > 1000;
2.
a) SELECT MIN(EventCost), MAX(EventCost), AVG(EventCost)

FROM Events;

b) SELECT COUNT(*) from

Events where LocationID='1' or LocationID='2';

c) SELECT AVG(EventCost)

FROM Events

WHERE LocationID='1';

d) SELECT * FROM Events

ORDER BY EventDate;

e) SELECT Sum(EventCost) FROM Events

GROUP BY LocationID Order By LocationID;

3.
a) SELECT Locations.LocationName, Events.EventID

FROM Locations

LEFT JOIN Events ON Locations.LocationID = Events.LocationID

ORDER BY Locations.LocationName Desc;

b) SELECT Locations.LocationName, Locations.Cost, Events.EventCost

FROM Locations

LEFT JOIN Events ON Locations.LocationID = Events.LocationID

Where Events.EventName='Zilele Folk';

c) SELECT Events.EventName, Locations.LocationName, Events.EventCost into NEWTABLE

FROM Events

inner JOIN Locations ON Locations.LocationID = Events.LocationID

SELECT * FROM NEWTABLE ORDER BY EventCost DESC

LIMIT 3;

You might also like