Query per aggiornare il fatturato
Tip scritto da
g2d
circa un anno fa
Due casi tipici
Così aggiorno il fatturato di uno specifico id se tutte le date sono antecedenti a oggi
1update interventi
2left join (
3select intervento,count(`data`) as quante,sum(if(`data` < curdate(),1,0)) as passate
4from uscite
5group by intervento
6) as tab
7on interventi.id = tab.intervento
8set interventi.fatturato = 100
9where id = 1 and tab.quante = tab.passate
Così aggiorno il fatturato di tutti gli id che hanno tutte le date antecedenti a oggi
1update interventi
2left join (
3select intervento,count(`data`) as quante,sum(if(`data` < curdate(),1,0)) as passate
4from uscite
5group by intervento
6) as tab
7on interventi.id = tab.intervento
8set interventi.fatturato = 100
9where tab.quante = tab.passate
- Current rating: 4.0/5
- 1
- 2
- 3
- 4
- 5
Tip precedente: Select per relazione molti a molti N a N
Tip successivo: Differenza date in minuti