Ciao Ragazzi,
ho questa tabella (FATTURE)
ID
TIPO
IMPORTO
STORNA
PAGATA
Praticamente siccome nella colonna storna ci vanno gli ID delle fatture stornate rispetto alla fattura, ESEMPIO:
1 FATTURA 30.00 SI SI
2 FATTURA 45.50 SI SI
3 FATTURA 20.00 SI SI
4 NC (NOTA CREDITO) 65.50 2,3 SI
5 NC 30.00 1 SI
Ossia tramite una procedura ho STORNATO insieme le fatture 2 e 3 nella nota di credito 4, quindi nella colonna STORNA della NC avrò 2,3 ossia che ha stornato le fatture 2 e 3!!
Mentre la NC 5 ha stornato la fattura numero 1
Ho questa Query:
SELECT SUM(t.importo) FROM (fattura INNER JOIN fattura AS t ON t.storna=fattura.id_fattura) WHERE fattura.pagata='SI'
Mi fa l'INNER JOIN della fattura 1 e 5, quindi riesco ad avere l'importo totale, ma come faccio a farlo per la nc 4 con le fatture 2 e 3???
Mi servirebbe una IF nell'INNER JOIN oppure un explode di php????? Oppure esiste un modo del genere: fattura INNER JOIN fattura AS t ON fattura.id_fattura IN t.storna ??????
Spero di essere stato chiaro.
HELP ME!!!!
Grazie
Ciro