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

Cerinta1: Datediff Month Getdate

The document contains the SQL code to create tables, views, stored procedures and constraints to manage bank account data. It defines tables for accounts, deposits, withdrawals and customers. Views and stored procedures are created to query and filter the data by things like gender, deposit amounts over time, number of accounts per customer and rankings of customers by total deposits.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Cerinta1: Datediff Month Getdate

The document contains the SQL code to create tables, views, stored procedures and constraints to manage bank account data. It defines tables for accounts, deposits, withdrawals and customers. Views and stored procedures are created to query and filter the data by things like gender, deposit amounts over time, number of accounts per customer and rankings of customers by total deposits.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

--cerinta1 create table RetrageriNUmerar (NrRetragere bigint primary key, DataRetragere date, SumaRetrasa money, NrCont bigint foreign

key references conturi(nrcont)) --cerinta2 alter table retragerinumerar add constraint ValoareSumaRetrasa check(sumaretrasa>= 1 and sumaretrasa<=1000) --cerinta3 alter view cerinta3 as select conturi.nrcont, left(conturi.cnp,1) as [sex], datediff(month, DataDepunere,getdate()) as [ultimele10luni], nume, prenume from conturi inner join depuneri on conturi.nrcont= depuneri.nrcont inner join persoane on conturi.cnp = persoane.cnp where left(conturi.cnp,1) = 1 and datediff(month, DataDepunere,getdate()) <=10 select * from cerinta3 --cerinta4 alter view cerinta4 as select sum(conturi.sumainitiala +depuneri.sumadepusa) as sumatotala, localitate from conturi inner join persoane on conturi.cnp = persoane.cnp inner join depuneri on conturi.nrcont=depuneri.nrcont group by localitate select * from cerinta4 --cerinta5
ALTER VIEW Cerinta5 AS SELECT Nume, COUNT(NrDepunere) AS NrDepuneri, COUNT(Distinct Conturi.NrCont) AS NumarConturi FROM Persoane LEFT JOIN Conturi ON Persoane.CNP = Conturi.CNP INNER JOIN Depuneri ON Conturi.NrCont = Depuneri.Nrcont GROUP BY Nume Select* from cerinta5

--cerinta6 & 7 alter proc cerinta6 (@sumainitiala as money) as begin select conturi.nrcont, persoane.cnp,localitate='bucuresti', datadeschiderii, sumainitiala from conturi inner join persoane on conturi.cnp=persoane.cnp where SumaInitiala>@sumainitiala order by DataDeschiderii asc end exec cerinta6 150

--cerinta8 alter proc cerinta8 as select count(nrcont) as TotalConturi,Nume from Persoane inner join Conturi on persoane.CNP=conturi.cnp group by Nume Having Count( NrCont )>2 order by TotalConturi asc exec cerinta8 --cerinta9 create proc cerinta9 (@datainitiala as date, @datafinala as date) as select conturi.nrcont, datadeschiderii, nume from conturi inner join persoane on conturi.cnp=persoane.cnp where datadeschiderii> @datainitiala and datadeschiderii<@datafinala order by nume asc exec cerinta9 '1.1.2011', '1.1.2012' --cerinta10 alter proc cerinta10 as select nume, prenume, conturi.nrcont, DENSE_RANK() OVER (ORDER BY sum(sumadepusa) asc) AS Clasamentsume, sumadepusa,DataDepunere from conturi inner join depuneri on conturi.nrcont=depuneri.nrcont inner join persoane on conturi.cnp=persoane.cnp where datadepunere > '1.1.2011' group by nume, prenume,conturi.nrcont, datadepunere, sumadepusa exec cerinta10

You might also like