-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViews.sql
141 lines (123 loc) · 4.61 KB
/
Views.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--Views
CREATE VIEW view_CityInDictionary as
select c.City, co.Country
from City as c
inner join Country as co
on c.CountryID = c.countryID
go
CREATE VIEW view_countriesInDictionary as
select c.Country
from Country as c
go
CREATE VIEW view_cancelledWorkshop as
select wd.WorkshopName, w.StartTime, w.EndTime,
cd.ConferenceDate
from Workshop as w
inner join WorkshopDictionary as wd
on wd.WorkshopDictionaryID = w.WorkshopDictionaryID
inner join ConferenceDay as cd
on cd.ConferenceDayID = w.ConferenceDayID
where w.cancelled = 1
go
--limit i wolne miejsca na nadchodzace konferencje (na kazdy dzien)
CREATE VIEW view_conferencesSeatsLeft as
select c.ConferenceID, c.ConferenceName, c.Limit, cd.ConferenceDate,
c.Limit -
isnull(((select sum(dr.NormalTickets)
from DayReservation as dr
where dr.ConferenceDayID = cd.ConferenceDayID)
+
(select sum(dr.StudentTickets)
from DayReservation as dr
where dr.ConferenceDayID = cd.ConferenceDayID)), 0) as 'Wolne miejsca'
from Conferences as c
inner join ConferenceDay as cd
on cd.ConferenceID = c.ConferenceID
where c.StartDate > getdate()
go
--wyswietla liczbe wolnych miejsc na nadchodzace warsztaty
--i calkowity limit miejsc
CREATE VIEW view_workshopsSeatLeft as
select w.WorkshopID, wd.WorkshopName,
cd.ConferenceDate, w.StartTime, w.EndTime,
w.Limit - SUM(wr.Tickets) AS 'Wolne miejsca',
w.Limit
from WorkshopDictionary as wd
inner join Workshop as w
on w.WorkshopDictionaryID = wd.WorkshopDictionaryID
inner join ConferenceDay as cd on
w.ConferenceDayID = cd.ConferenceDayID
inner join WorkshopReservation as wr
on w.WorkshopID = wr.WorkshopID
where cd.ConferenceDate > GETDATE() and w.Cancelled <> 1
group by w.WorkshopID, wd.WorkshopName,
cd.ConferenceDate, w.StartTime, w.EndTime, w.Limit
go
CREATE VIEW view_workshopDictionary as
select wd.WorkshopName, wd.WorkshopDescription, wd.Price
from WorkshopDictionary as wd
go
--fix here
/*
--informacje o nadchodzacyh konferencjach
CREATE VIEW view_conferencesInfo as
select c.ConferenceName, c.ConferenceDescription, c.limit, c.StartDate, c.EndDate,
c.BuildingNumber,c.street, ci.City, co.Country,
c.BasePrice*(1-isnull(p.Discount, 0)) as 'Normal ticket price',
c.BasePrice*(1-isnull(p.Discount, 0))*(1-c.StudentDiscount) as 'Student ticket price'
from Conferences as c
inner join City as ci on ci.CityID = c.CityID
inner join Country as co on co.CountryID = ci.CountryID
left outer join prices as p on p.ConferenceID = c.ConferenceID and
GETDATE() between p.StartDate and p.EndDate
where c.StartDate >= getdate()
go
*/
--wyswietla rezerwacje ktore powinny zostac usuniete
CREATE VIEW view_reservationOnConferenceToDelete as
select r.ReservationID, r.ClientID, dr.NormalTickets, dr.StudentTickets,
DATEADD(day, 7, r.ReservationDate) as 'Payment deadline',
c.ConferenceID, c.ConferenceName
from Reservation as r
inner join DayReservation as dr
on dr.ReservationID = r.ReservationID
inner join ConferenceDay as cd
on cd.ConferenceDayID = dr.ConferenceDayID
inner join Conferences as c
on c.ConferenceID = cd.ConferenceID
where PaymentDate is null and
DATEDIFF(day, DATEADD(day, 7, r.ReservationDate), GETDATE()) > 0
go
--firmy, ktore nie uzupelnily wszystkich uczestnikow 2 tygodnie przed konferencja
CREATE VIEW view_companiesYetToFillEmployees as
select com.ClientID, com.CompanyName, com.NIP, cl.Email, cl.Phone
from Company as com
inner join Clients as cl on cl.ClientID = com.ClientID
inner join Reservation as r on r.ClientID = cl.ClientID
inner join DayReservation as dr on dr.ReservationID = r.ReservationID
inner join ConferenceDay as cd on cd.ConferenceDayID = dr.ConferenceDayID
inner join Conferences as c on c.ConferenceID = cd.ConferenceID
where datediff(day, getdate(), c.StartDate) <= 14 and exists
(select *
from Employee as e
inner join Person as p
on e.PersonID = p.PersonID
inner join DayParticipant as dp2
on dp2.PersonID = p.PersonID and
dp2.DayReservationID = dr.DayReservationID
where e.Firstname is null or e.Lastname is null
)
go
--wyswietla nadchodzace warsztaty
CREATE VIEW view_upcomingWorkshops as
select w.WorkshopID, wd.WorkshopName, wd.WorkshopDescription, w.Limit, wd.Price,
c.ConferenceID, c.ConferenceName, cd.ConferenceDate, w.StartTime, w.EndTime
from Workshop as w
inner join WorkshopDictionary as wd
on wd.WorkshopDictionaryID = w.WorkshopDictionaryID
inner join ConferenceDay as cd
on cd.ConferenceDayID = w.ConferenceDayID
inner join Conferences as c
on c.ConferenceID = cd.ConferenceID
where (cd.ConferenceDate > GETDATE() and w.Cancelled <> 1)
go