Answer the question
In order to leave comments, you need to log in
I want to hear opinions about scripts?
There is such a diagram of the database, I hope the names of the fields + - the connections between the tables are clear.
The task itself is as follows: Implement scripts to get the following information 1. The
current rating of players in descending order
2. The last N changes in the player's rating
3. The last N matches of the player
4. The last N personal meetings between two players
5. The final table of the tournament
6. All tournament matches in chronological order
And here are the scripts themselves
/* Part1*/
select * from Players order by -rating
/* Part2*/
select top(3)
P.nick,
M.date,
R.old_rating,
R.new_rating
from Players P
join Change_Rating R on(P.id=4) and(P.id=R.id_pl)
join Matches M on(R.id_M=M.id)
order by M.date DESC
/* Part3*/
select top(2)
P.nick,
M.date
from Matches M
join Players P on(P.id=M.id_pl1 or P.id=M.id_pl2) and P.id=4
order by M.date DESC
/* Part4*/
select top(2)
F.nick,
S.nick,
M.date
from Matches M
join Players F on(M.id_pl1=F.id or M.id_pl2=F.id) and(F.id=4)
join Players S on(M.id_pl2=S.id or M.id_pl1=S.id) and(S.id=6)
order by M.date DESC
/* Part5*/
select
P.nick,
T.points
from(
select
R.id_pl,
sum(R.new_rating - R.old_rating) as points
from Tournaments T
join Matches M on(T.id=M.id_T) and (T.id=2)
join Change_Rating R on(R.id_M=M.id)
group by R.id_pl
) as T
join Players P on(P.id=T.id_pl)
order by -T.points
/* Part6*/
select
F.nick,
S.nick,
M.date
from Matches M
join Tournaments T on(M.id_T=T.id)and(T.id=1)
join Players F on(F.id=M.id_pl1)
join Players S on(S.id=M.id_pl2)
order by M.
Answer the question
In order to leave comments, you need to log in
Players_Tournaments
superfluous, all players of the tournament are in Matches
.
Dates are Tournaments
not needed, all dates are in Matches
.
Optional: do not save characters, all fields can be called by the full name.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question