select s.godina, count(*) as broj_odigranih_utakmica
from utakmice u
inner join sezona s
on u.id_sezone = s.id
group by s.godina
select id_igraca, DATEDIFF(Day, datum1, datum2) as 'broj_dana'
from ugovori
where DATEDIFF(Day, datum1, datum2) =
(
select MAX(DATEDIFF(day, u.datum1, u.datum2))
from ugovori u
)
select i.ime,
(
select count(*)
from golovi g
where g.id_igraca = i.id
) as broj_golova
from igraci i
select s.godina, ug.id_igraca, count(*)
from utakmice ut
inner join sezona s
on ut.id_sezone = s.id
inner join ugovori ug
on ug.id_tima in (ut.id_domacina, ut.id_gosta) and
s.godina between year(ug.datum1) and year(ug.datum2)
group by s.godina, ug.id_igraca
having count(*) > 3
select u.id, d.naziv, g.naziv, concat(
(
select count(*)
from golovi g1
where g1.id_utakmice = u.id and g1.id_tima = u.id_domacina
),
':',
(
select count(*)
from golovi g2
where g2.id_utakmice = u.id and g2.id_tima = u.id_gosta
)) as rezultat
from utakmice u
inner join timovi d
on u.id_domacina = d.id
inner join timovi g
on u.id_gosta = g.id
go
create view autoGolovi
as
select g.id_igraca, i.ime, count(*) as 'broj_auto_golova'
from golovi g
inner join igraci i
on g.id_igraca = i.id
inner join utakmice u
on g.id_utakmice = u.id
inner join sezona s
on u.id_sezone = s.id
inner join ugovori ug
on
g.id_igraca = ug.id_igraca and
g.id_tima != ug.id_tima and
s.godina between year(ug.datum1) and year(ug.datum2)
group by g.id_igraca, i.ime
go
select ime, broj_auto_golova
from autoGolovi
where broj_auto_golova =
(
select max(broj_auto_golova)
from autoGolovi
)