Professional Documents
Culture Documents
New Text Document
New Text Document
-- MSSV: 2011062839
-- LỚP : 20DTHC4
create database QUANLYBONGDA
go
use QUANLYBONGDA
go
create table doi
(
madoi char(3) unique ,
TENdoi nvarchar(50) not null,
primary key(madoi),
)
create table trandau
(
matd char(2) primary key not null,
masan char(3) not null,
ngay date not null,
gio time not null,
)
create table ct_trandau
(
matd char(2) not null ,
madoi char(3) not null,
sobanthang tinyint not null check (sobanthang >=0),
primary key(matd,madoi),
foreign key(matd) references trandau(matd)
on update cascade
on delete no action,
foreign key(madoi) references doi(madoi)
on update cascade
on delete no action
)
log on
(
size = 200
,filegrowth = 20
,maxsize = unlimited
,filename = 'C:\DB\QLBONGDA.LDF'
,name = QLBONGDA_Log
)
USE QLBONGDA
create table Doi
(
MaDoi char(3) primary key not null,
TenDoi nvarchar(50) not null,
)
log on
(
size = 200
,filegrowth = 20
,maxsize = unlimited
,filename = 'C:\DB\QLBONGDA.LDF'
,name = QLBONGDA_Log
)
USE QLBONGDA
SELECT a.matd,a.madoi,diem=case
when a.sobanthang>b.sobanthang then 3
when a.sobanthang=b.sobanthang then 1
else 0 end
from ct_trandau a,ct_trandau b
where a.matd=b.matd and a.madoi!=b.madoi
......................................................
log on
(
size = 200
,filegrowth = 20
,maxsize = unlimited
,filename = 'C:\DB\QLBONGDA.LDF'
,name = QLBONGDA_Log
)
USE QLBONGDA
--/Cau 1
select Doi.MaDoi, TenDoi, count(MaTD) as 'Số Trận Đấu'
from Doi,CT_TranDau
where Doi.MaDoi = CT_TranDau.MaDoi
group by Doi.MaDoi,TenDoi
--/Cau 2
select A.MaTD as 'Ma Tran', concat(A.MaDoi,'-', B.MaDoi) as 'Đội Trận Đấu',
concat(A.SoBanThang,'-',B.SoBanThang) as 'Tỷ Số'
from CT_TranDau A, CT_TranDau B
where A.MaTD = B.MaTD and A.MaDoi > B.MaDoi
--/Cau 3
select A.MaTD,A.MaDoi,Diem=case
when A.SoBanThang > B.SoBanThang then 3
when A.SoBanThang = B.SoBanThang then 1
else 0 end
from CT_TranDau A,CT_TranDau B
where A.MaTD = B.MaTD and A.MaDoi != B.MaDoi
--/Cau 6
select concat(A.MaDoi,'-', B.MaDoi) as 'Trận chưa đá'
from CT_TranDau A, CT_TranDau B, Doi, TranDau
where A.MaDoi > B.MaDoi
except
select concat(A.MaDoi,'-', B.MaDoi) as 'Trận chưa đá'
from CT_TranDau A, CT_TranDau B, Doi, TranDau
where A.MaDoi > B.MaDoi and A.MaTD = B.MaTD