Question 1) : Update

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

--Question 1}

create database TP2015


use TP2015

create table Abonne (idAbonne int primary key,


nomAb varchar(50),
TelAab varchar ,
pass varchar)

create table Usage(idUsage int primary key,


NomUsaoe varchar(50)
,montantUsage float)

create table Abonnement(idAbonnement int primary key


,dateAb varchar(50)
,idUsage int foreign key references Usage(idUsage)
, idAbonne int foreign key references Abonne (idAbonne))

create table Tranches(NumTranche int identity primary key


,ValMin int
,ValMax int
,PU float)

create table Consommation(idconsommation int primary key


,periode date
,Qte int
,idAbonnement int foreign key references
Abonnement(idAbonnement))

if Not Exists(select * from Tranches where ValMax>500)


insert into Tranches(ValMin,ValMax,PU )values(0,100,0.9010),(101,150,0.9589 ),
(151,200,0.9689),
(201,300,1.0541),(301,500,1.2474),
(501,' ',1.4407)
Else
Update Tranches set Pu=1.4407 where ValMax>500

--Question 2}

select abm.idAbonnement,sum(Qte) Total, ab.nomAb


from Consommation c join Abonnement abm on c.idAbonnement=abm.idAbonnement join
Abonne ab on abm.idAbonne=ab.idAbonne
Where DATEPART(YEAR,periode)='2014' group by abm.idAbonnement,ab.nomAb

--Question 3}

create function Question3(@code int)


returns date
as
begin
return (select periode from Consommation C
Join Consomaton C1 on C.idconsommation=C1.idConsommation
where C.Max(Qte)>C1.Max(Qte) and idAbonnement=@code)

end
--Question 4}

create function Question4(@code int)


returns date
as
begin
return (select NumTranche from Tranches T
Join Tranches T1 on T.NumTranche=T1.NumTranche
where T.Max(ValMax)>T1.Max(ValMax) and NumTranche=@code)

end

--Question 5}
create procedure t5(@Code int)
AS
begin
select periode,Qte from Consommation c where Exists (select NumTranche from
Tranches t where t.NumTranche=c.idconsommation)
Group by t.NumTranche
end

You might also like