Leggiti questo thread
http://forum.html.it/forum/showthrea...ght=campionato
questo sì "secolare".
Leggiti questo thread
http://forum.html.it/forum/showthrea...ght=campionato
questo sì "secolare".
mah si, volendo puoi farti anche le varie tabelle per differenziare le stagioni/squadre/ecc, ma in ogni caso (o almeno, io avevo ragionato così) avrai una tabella calendario con (per ogni riga) le due squadre che giocano, il risultato, che giornata, che campionato, ecc...Originariamente inviato da michefra
ok, io lo sto popolando in mysql
ammesso che voglio creare un database con stagioni e più campionati
devo creare la tabella "calendario" (come sopra) e devo avre le seguenti tabelle:
create table "stagioni" (
id int(11) unsigned not null auto_increment,
anno year not null,
primary key (id));
create table "giornata" (
id int(11) unsigned not null auto_increment,
squadra_casa varchar(30) not null,
squadra_fuori varchar(30) not null,
risultato_sqd.casa int(2) unsigned not null,
risultato_sqd.fuori int(2) unsigned not null,
numero_giornata int(2) unsigned not null,
primary key(id));
create table squadre (
id int(11) unsigned not null auto_increment,
nome varchar(30) not null,
primary key(id));
te hai fatto così???
adesso se volessi avere anche il minuto del gol e il nome del giocatore??
dovrei aggiungere alla tabella "giornata"
min.gol int(3) not null,
nome_giocatore varchar(30) not null,
e creare la tabella giocatori perònon riesco a capire come fare...![]()
poi sfogli/aggiorni quella. no?
Salve. Risollevo questo topic perchè ho bisogno di un ulteriore "spunto".
Ho fatto una modifica al comportamento usuale, inserendo (al posto di "-" o "n", che sarebbe il numero di gol per ogni v1/v2) una "s" (che stà per partita sospesa). Ovviamente se è sospesa entrambi v1 e v2 avranno "s" (tramite un controllo fatto con php prima di inserire i risultati).
Ho quindi modificato la query di conseguenza :
sembra funzionare. Il problema è che nel conteggio delle partite giocate (totali fuori casa/casa vinte/perse/nulle, solo in casa o solo fuori casa) se la partita è sospesa me la conta come PERSE.codice:select squadra, sum(punteggio) as punti, sum(if(fatti!='-',1,0)) as gioc, sum(if(punteggio=3,1,0)) as vt, sum(if(punteggio=1,1,0)) as nt, sum(if(punteggio=0 and fatti != '-',1,0)) as pt, sum(if(punteggio=3 and dove = 'C',1,0)) as vc, sum(if(punteggio=1 and dove = 'C',1,0)) as nc, sum(if(punteggio=0 and dove = 'C' and fatti != '-',1,0)) as pc, sum(if(punteggio=3 and dove = 'T',1,0)) as vf, sum(if(punteggio=1 and dove = 'T',1,0)) as nf, sum(if(punteggio=0 and dove = 'T' and fatti != '-',1,0)) as pf, abs(sum(fatti)) as gtf, abs(sum(subiti)) as gts, sum(if(dove='C',fatti,0)) as gfc, sum(if(dove='C',subiti,0)) as gsc, sum(if(dove='T',fatti,0)) as gff, sum(if(dove='T',subiti,0)) as gsf, (sum(if(punteggio=1 and dove = 'C',1,0)) * -2) + (sum(if(punteggio=0 and dove = 'C' and fatti != '-',1,0)) * -3) + (sum(if(punteggio=3 and dove = 'T',1,0)) * 2) - (sum(if(punteggio=0 and dove = 'T' and fatti != '-',1,0))) as mi from ( select team1 as squadra, v1 as fatti, v2 as subiti,'C' as dove, case when v1 > v2 then 3 when v1 = v2 and v1 <> '-' and v1 <> 's' then 1 else 0 end as punteggio from calendario union all select team2 as squadra, v2 as fatti,v1 as subiti,'T', case when v2 > v1 then 3 when v2 = v1 and v2 <> '-' and v2 <> 's' then 1 else 0 end as punteggio from calendario ) as tab group by squadra order by punti desc
Come posso risolvere?
Saluti![]()
Non ho provato ma andando per logica dovrebbe bastare.![]()
codice:select squadra, sum(punteggio) as punti, sum(if(fatti!='s',1,0)) as gioc, sum(if(punteggio=3,1,0)) as vt, sum(if(punteggio=1,1,0)) as nt, sum(if(punteggio=0 and fatti != '-',1,0)) as pt, sum(if(punteggio=3 and dove = 'C',1,0)) as vc, sum(if(punteggio=1 and dove = 'C',1,0)) as nc, sum(if(punteggio=0 and dove = 'C' and fatti != 's',1,0)) as pc, sum(if(punteggio=3 and dove = 'T',1,0)) as vf, sum(if(punteggio=1 and dove = 'T',1,0)) as nf, sum(if(punteggio=0 and dove = 'T' and fatti != 's',1,0)) as pf, abs(sum(fatti)) as gtf, abs(sum(subiti)) as gts, sum(if(dove='C',fatti,0)) as gfc, sum(if(dove='C',subiti,0)) as gsc, sum(if(dove='T',fatti,0)) as gff, sum(if(dove='T',subiti,0)) as gsf, (sum(if(punteggio=1 and dove = 'C',1,0)) * -2) + (sum(if(punteggio=0 and dove = 'C' and fatti != 's',1,0)) * -3) + (sum(if(punteggio=3 and dove = 'T',1,0)) * 2) - (sum(if(punteggio=0 and dove = 'T' and fatti != 's',1,0))) as mi from ( select team1 as squadra, v1 as fatti, v2 as subiti,'C' as dove, case when v1 > v2 then 3 when v1 = v2 and v1 <> 's' then 1 else 0 end as punteggio from calendario union all select team2 as squadra, v2 as fatti,v1 as subiti,'T', case when v2 > v1 then 3 when v2 = v1 and v2 <> 's' then 1 else 0 end as punteggio from calendario ) as tab group by squadra order by punti desc
uhm il fatto è che avrò sia "-" che "s"...
"-" non li conta (deve ancora essere giocata)... "s" non li deve contare comunque (è stata sospesa)...
Vedi un pò se i conti tornano.
codice:select squadra, sum(punteggio) as punti, sum(if(fatti!='-' and fatti != 's',1,0)) as gioc, sum(if(punteggio=3,1,0)) as vt, sum(if(punteggio=1,1,0)) as nt, sum(if(punteggio=0 and fatti != '-' and fatti != 's' ,1,0)) as pt, sum(if(punteggio=3 and dove = 'C',1,0)) as vc, sum(if(punteggio=1 and dove = 'C',1,0)) as nc, sum(if(punteggio=0 and dove = 'C' and fatti != '-' and fatti != 's',1,0)) as pc, sum(if(punteggio=3 and dove = 'T',1,0)) as vf, sum(if(punteggio=1 and dove = 'T',1,0)) as nf, sum(if(punteggio=0 and dove = 'T' and fatti != '-' and fatti != 's',1,0)) as pf, abs(sum(fatti)) as gtf, abs(sum(subiti)) as gts, sum(if(dove='C',fatti,0)) as gfc, sum(if(dove='C',subiti,0)) as gsc, sum(if(dove='T',fatti,0)) as gff, sum(if(dove='T',subiti,0)) as gsf, (sum(if(punteggio=1 and dove = 'C',1,0)) * -2) + (sum(if(punteggio=0 and dove = 'C' and fatti != '-' and fatti != 's',1,0)) * -3) + (sum(if(punteggio=3 and dove = 'T',1,0)) * 2) - (sum(if(punteggio=0 and dove = 'T' and fatti != '-' and fatti != 's',1,0))) as mi from ( select team1 as squadra, v1 as fatti, v2 as subiti,'C' as dove, case when v1 > v2 then 3 when v1 = v2 and v1 <> '-' and v1 <> 's' then 1 else 0 end as punteggio from calendario union all select team2 as squadra, v2 as fatti,v1 as subiti,'T', case when v2 > v1 then 3 when v2 = v1 and v2 <> '-' and v2 <> 's' then 1 else 0 end as punteggio from calendario ) as tab group by squadra order by punti desc
sembra funzionare! Grazie mille, sei stato davvero gentilissimo![]()
Rialzo il topic perchè dovrei aggiungere una nuova funzionalità alla mia query :
la mia tabella calendario oltre a team1, team2, v1 e v2 ha anche un'altro campo, chiamato campionato, che è un ID che corrisponde ad un determinato campionato.
Per esempio : tutte le righe del campionato 2009-2010 hanno campionato=1; 2010-2011 campionato=2; e via così...
Come posso estrarre i risultati, per esempio, del campionato=2?
Io ho provato a ri-metterci mano ma mi dà continui errori
Spero non sia troppo tardi per questa richiesta, ehehe (son passati molti mesi)![]()
Ho risolto (grazie ad un utente di SO) con :
Sembra andar benecodice:select squadra, sum(punteggio) as punti, sum(if(fatti!='-' and fatti != 's',1,0)) as gioc, sum(if(punteggio=3,1,0)) as vt, sum(if(punteggio=1,1,0)) as nt, sum(if(punteggio=0 and fatti != '-' and fatti != 's' ,1,0)) as pt, sum(if(punteggio=3 and dove = 'C',1,0)) as vc, sum(if(punteggio=1 and dove = 'C',1,0)) as nc, sum(if(punteggio=0 and dove = 'C' and fatti != '-' and fatti != 's',1,0)) as pc, sum(if(punteggio=3 and dove = 'T',1,0)) as vf, sum(if(punteggio=1 and dove = 'T',1,0)) as nf, sum(if(punteggio=0 and dove = 'T' and fatti != '-' and fatti != 's',1,0)) as pf, abs(sum(fatti)) as gtf, abs(sum(subiti)) as gts, sum(if(dove='C',fatti,0)) as gfc, sum(if(dove='C',subiti,0)) as gsc, sum(if(dove='T',fatti,0)) as gff, sum(if(dove='T',subiti,0)) as gsf, (sum(if(punteggio=1 and dove = 'C',1,0)) * -2) + (sum(if(punteggio=0 and dove = 'C' and fatti != '-' and fatti != 's',1,0)) * -3) + (sum(if(punteggio=3 and dove = 'T',1,0)) * 2) - (sum(if(punteggio=0 and dove = 'T' and fatti != '-' and fatti != 's',1,0))) as mi from ( ( select team1 as squadra, v1 as fatti, v2 as subiti,'C' as dove, case when v1 > v2 then 3 when v1 = v2 and v1 <> '-' and v1 <> 's' then 1 else 0 end as punteggio from calendario WHERE campionato = 2 ) union all ( select team2 as squadra, v2 as fatti,v1 as subiti,'T', case when v2 > v1 then 3 when v2 = v1 and v2 <> '-' and v2 <> 's' then 1 else 0 end as punteggio from calendario campionato = 2 ) ) as tab group by squadra order by punti desc![]()
Ciao a tutti!
Sto usando questo codice SQL per la mia classifica e avrei bisogno di aggiungere la possibilità che il punteggio tenga conto dei punti di penalizzazione, che ho salvato in una tabella chiamata 'campionati_SerieA' in una colonna chiamata 'penalita'.
Qualsiasi aiuto è ben accetto!
Grazie
Ciaooo
Tiziano