-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.sql
34 lines (31 loc) · 1.42 KB
/
view.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
if OBJECT_ID('dbo.vAlp') is not null
begin
drop view dbo.vAlp
end
go
--Kullanıcının hesabıyla ilgili temel verileri (id'si, adı, cüzdan bakiyesinin büyüklüğü, sattığı en karlı eşyanın ismi,
--eşyayı aldığı tarih, eşyayı sattığı tarih, eşyanın satışından elde ettiği kar) getiren view
create view vAlp
as
select k.ID, k.kullaniciAdi as [Kullanıcı Adı],
case when k.Cuzdan>=1990 then 'Ortalama üstü bakiye'
when k.Cuzdan between 1500 and 1990 then 'Ortalama bakiye'
else 'Ortalama altı bakiye'
end as [Bakiye Miktarı], e.isim as [Eşya İsmi],
convert(varchar,ek.alisTarihi,5) as [Alış Tarihi],
convert(varchar,ek.satisTarihi,5) as [Satış Tarihi],
round(max(satisFiyati-alisFiyati),2) as [Max Kar]
from Kullanici k
inner join EnvanterKaydi ek on ek.kullaniciID=k.ID
inner join Esya e on e.ID=ek.esyaID
where ek.ID=dbo.maxKar(k.ID)
group by k.ID, k.kullaniciAdi,k.Cuzdan,e.isim,ek.alisTarihi,ek.satisTarihi
go
--View'e ek olarak sepetindeki oyunların sayısı, sepetteki oyunların toplam fiyatı
select valp.ID,[Kullanıcı Adı], [Bakiye Miktarı], vAlp.[Eşya İsmi], [Alış Tarihi], [Satış Tarihi],[Max Kar],
count(se.kullaniciID) as [Sepetteki Ürün Sayısı], round(sum(o.fiyat),2) as [Sepet Tutarı]
from vAlp
inner join SepeteEkle se on se.kullaniciID=vAlp.ID
inner join Oyun o on se.oyunID=o.ID
group by vAlp.ID,[Bakiye Miktarı],vAlp.[Eşya İsmi],[Alış Tarihi],[Satış Tarihi],[Kullanıcı Adı],[Max Kar]
order by vAlp.ID