-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewKullanim.sql
92 lines (61 loc) · 2.87 KB
/
ViewKullanim.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
use VTDERS21EKIM
--SORU1 : Personel tablosunda VIEW_AD_SOYAD view oluþtur. ayný soruyu isminde sorguyu gizleyecek þekilde GIZLI_VIEW_AD_SOYAD isminde view oluþturalým.
-- view içeriðini gösterelim.
create view VIEW_AD_SOYAD
as
(select personel.isim, personel.soyisim from personel);
select * from VIEW_AD_SOYAD
-- Gizli view oluþturma
create view GIZLI_VIEW_AD_SOYAD with encryption
as
(select personel.isim, personel.soyisim from personel);
select * from GIZLI_VIEW_AD_SOYAD; -- içine müdahale edilemeyen deðiþtirilemeyen view oluþturduk.
-- SORU 2 : view_maas_rapor þeklinde view min, max, ort, toplam maaþý göstersin
create view view_maas_rapor
as
(select min(maas) as MinMaas, max(maas) as MaxMaas, avg(maas) as OrtMaas, sum(maas) as ToplamMaas from personel);
select * from view_maas_rapor
-- SORU 3 : view_maas_rapor view'ýna yeni bir alan ekleme. Deðiþiklik yapma alter view --viewadi--
alter view view_maas_rapor
as
(select count(*) as ToplamKisiSayisi, min(maas) as MinMaas, max(maas) as MaxMaas, avg(maas) as OrtMaas, sum(maas) as ToplamMaas from personel);
select * from view_maas_rapor
-- SORU 4 : Kitap adýnda Q olanlarý gösterelim view'da
create view view_kitap_yazar
as
(select isim from kitaplar where isim like ('%Q%'));
select * from view_kitap_yazar;
-- Hocanýn yaptýðý farklý soru sanýrým Q eklemeden yazdý.
create view view_kitap_yazar2
as
(select yazarlar.isim as YazarIsim, YAZARLAR.soyisim as YazarSoyisim, kitaplar.isim as KitapIsim from kitaplar, yazarlar, kyazarlar
where kitaplar.no = kyazarlar.no and
yazarlar.yazar_no = kyazarlar.NO and
kitaplar.isim like ('%Q%'));
select * from view_kitap_yazar2;
----
create view view_kitap_yazar3
as
(select yazarlar.isim as YazarIsim, YAZARLAR.soyisim as YazarSoyisim, kitaplar.isim as KitapIsim from kitaplar, yazarlar, kyazarlar
where kitaplar.no = kyazarlar.no and
yazarlar.yazar_no = kyazarlar.NO );
select * from view_kitap_yazar3 v where v.KitapIsim like ('%Q%');
-- SORU 5 : genel maas view'ý ile personelin ortalama maþýný bulalým
create view view_genel_maas
as
(select avg(maas) as OrtMaas from personel);
select * from view_genel_maas
select * from personel where maas>(select * from view_genel_maas);
-- OR
select * from personel p, view_genel_maas v where maas>v.OrtMaas order by maas asc;
-- TOP : Ortalamadan düþük en yüksek maaþ
select top 1 * from personel p, view_genel_maas v where maas<v.OrtMaas order by maas asc;
-- TOP : Ortalamadan yüksek en düþük maaþ
select top 1 * from personel p, view_genel_maas v where maas<v.OrtMaas order by maas asc;
-- SORU 6 : Ülkesindeki ort maaþtan daha yüksek maaþ alan personel
create view view_ulke_maas
as
select ulke, avg(maas) as OrtMaas from personel group by ulke;
select * from view_ulke_maas;
select * from personel p, view_ulke_maas v where p.maas>v.OrtMaas
and p.ulke=v.ulke