MagicBuzz | Dans cet exemple aussi si tu préfères :
Code :
SELECT p.codpro "Code Article", p.nompro "Désignation", p.codblocage "Statut", p.gencod "EAN13", p.ssfpro "Collection", d2.c01 "DPT2", d3.c02 "DPT3" FROM pro p INNER JOIN dsk d2 ON d2.codsoc = p.codsoc AND d2.sigdep = 'DPT2' AND d2.codpro = p.codpro INNER JOIN dsk d3 ON d3.codsoc = p.codsoc AND d3.sigdep = 'DPT2' AND d3.codpro = p.codpro WHERE p.codsoc = 2 AND p.suistk = 'S'
|
Ou celui-ci si tu préfère :
Code :
SELECT sigtie, nomtie, sigdep, libfam, codpro, design1, stk, codblocage, pump, 'EUR' coddevp, vtar, coddevv, atar, coddeva, rev, coddevr FROM ( SELECT pro.sfapro, pro.ssfpro, dsk.codsoc, tie.sigtie, tie.nomtie, prc.refpro, pro.codpro, pro.design1, pro.codblocage, pro.ssfpro, dsk.sigdep, dsk.C01 + (dsk.C04 + dsk.C05) - (dsk.C02 + dsk.C03) stk, dsk.pump, vtar.prxtar vtar, vtar.coddev coddevv, atar.prxtar atar, atar.coddev coddeva, rtar.prxrev rev, rtar.coddev coddevr, fam.libfam FROM fam, dsk, pro, tie, prc, tsc vtar, tsc atar, tsc rtar WHERE pro.codsoc = dsk.codsoc AND pro.codpro = dsk.codpro AND pro.codblocage <> 'SOM' AND fam.codsoc = pro.codsoc AND fam.codefam = pro.fampro AND fam.codesfa = pro.sfapro AND fam.codessf = pro.ssfpro AND tie.codsoc = pro.codsoc AND tie.typtie ='FOU' AND tie.sigtie = pro.sigfou AND prc.codsoc = pro.codsoc AND prc.codpro = pro.codpro AND prc.typtie = 'FOU' AND prc.sigfou = tie.sigtie AND (dsk.c01 > 0 OR dsk.C04>0 OR dsk.C05>0 OR dsk.C02>0 OR dsk.C03>0) AND vtar.codsoc(+)=dsk.codsoc AND vtar.achvte(+)='V' AND vtar.sigtie(+)=' ' AND vtar.codpro(+)=dsk.codpro AND vtar.coddev(+)='EUR' AND nvl(vtar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='V' AND tsc.sigtie=' ' AND tsc.codpro=dsk.codpro AND tsc.coddev='EUR') AND atar.codsoc=dsk.codsoc AND atar.achvte='A' AND atar.codpro=dsk.codpro AND atar.coddev=tie.coddev AND nvl(atar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='A' AND tsc.codpro=dsk.codpro AND tsc.coddev=atar.coddev ) AND rtar.codsoc(+)=dsk.codsoc AND rtar.achvte(+)='R' AND rtar.codpro(+)=dsk.codpro AND rtar.coddev(+)='EUR' AND nvl(rtar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='R' AND tsc.codpro=dsk.codpro AND tsc.coddev='EUR') union SELECT pro.sfapro, pro.ssfpro, dsk.codsoc, tie.sigtie, tie.nomtie, prc.refpro, pro.codpro, pro.design1, pro.codblocage, pro.ssfpro, dsk.sigdep, dsk.C01 + (dsk.C04 + dsk.C05) - (dsk.C02 + dsk.C03), dsk.pump, vtar.prxtar vtar, vtar.coddev coddevv, atar.prxtar atar, atar.coddev coddeva, rtar.prxrev rev, rtar.coddev coddevr, fam.libfam FROM fam, dsk, pro, tie, prc, tsc vtar, tsc atar, tsc rtar WHERE pro.codsoc = dsk.codsoc AND pro.codpro = dsk.codpro AND pro.codblocage <> 'SOM' AND fam.codsoc = pro.codsoc AND fam.codefam = pro.fampro AND fam.codesfa = pro.sfapro AND fam.codessf = pro.ssfpro AND tie.codsoc = pro.codsoc AND tie.typtie ='FOU' AND tie.sigtie = pro.sigfou AND prc.codsoc = pro.codsoc AND prc.codpro = pro.codpro AND prc.typtie = 'FOU' AND prc.sigfou = tie.sigtie AND dsk.sigdep = pro.sigdep AND vtar.codsoc(+)=dsk.codsoc AND vtar.achvte(+)='V' AND vtar.sigtie(+)=' ' AND vtar.codpro(+)=dsk.codpro AND vtar.coddev(+)='EUR' AND nvl(vtar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='V' AND tsc.sigtie=' ' AND tsc.codpro=dsk.codpro AND tsc.coddev='EUR') AND atar.codsoc=dsk.codsoc AND atar.achvte='A' AND atar.codpro=dsk.codpro AND atar.coddev=tie.coddev AND nvl(atar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='A' AND tsc.codpro=dsk.codpro AND tsc.coddev=atar.coddev ) AND rtar.codsoc(+)=dsk.codsoc AND rtar.achvte(+)='R' AND rtar.codpro(+)=dsk.codpro AND rtar.coddev(+)='EUR' AND nvl(rtar.datdeb, to_char(sysdate, 'YYYYMMDD'))=(SELECT nvl(max(tsc.datdeb),to_char(sysdate,'YYYYMMDD')) FROM tsc WHERE tsc.codsoc=dsk.codsoc AND tsc.achvte='R' AND tsc.codpro=dsk.codpro AND tsc.coddev='EUR') ) WHERE codsoc = 2 AND sfapro = 'TEXT' --and sigtie = 'NANDINI' AND sigdep IN ('DPT1', 'DPT6') ORDER BY sigtie, nomtie, libfam, codpro
|
Ou encore celle-là :
Code :
SELECT mev.codsoc, msk.codpro, pro.fampro, pro.sfapro, pro.ssfpro, pro.nompro, msk.codosk, msk.achvte, msk.typeve, nvl(ret.typtie, ' '), nvl(ret.sigtie, ' '), nvl(ret.refext, ' '), nvl(rettn.commen1, ' '), nvl(rettn.commen2, ' '), nvl(rettn.commen3, ' '), nvl(rettn.commen4, ' '), nvl(ent.sigdep, ' '), ' ', ' ', ' ', ' ', msk.datmvt, ' ', ' ', ' ', ' ', msk.numeve, decode(msk.codosk, 'ENTREE', msk.qteope, 'TRFENT', msk.qteope, 'INICPT', msk.qteope, 'INIT', msk.qteope, 'VREAVN', -1*msk.qteope, 0) "Entrées", decode(msk.codosk, 'TRFSOR', msk.qteope, 'VLIVVN', msk.qteope, 0) "Réparés", decode(msk.codosk, 'SORTIE', msk.qteope, 0) "Détruits", sum(faa.qtecde) afaa, 0, 0, 0, 0, 0, msk.prxvte, msk.prxrev, tsc.prxtar, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 FROM mev INNER JOIN msk ON msk.codsoc = fct_mev(mev.codsoc, 'MSK', ' ') INNER JOIN pro ON pro.codsoc = fct_mev(msk.codsoc, 'PRO', ' ') AND pro.codpro = msk.codpro INNER JOIN tsc ON tsc.codsoc = fct_mev(pro.codsoc, 'TSC', 'V') AND tsc.codpro = pro.codpro AND tsc.achvte = 'V' INNER JOIN evp faa ON faa.codsoc = fct_mev(msk.codsoc, 'EVP', ' ') AND faa.achvte = 'A' AND faa.typeve = 'FAA' AND faa.codpro = pro.codpro LEFT OUTER JOIN msk ent ON ent.codsoc = fct_mev(msk.codsoc, 'MSK', ' ') AND ent.codpro = msk.codpro AND ent.datmvt = msk.datmvt AND ent.heumvt = msk.heumvt AND ent.codosk = 'TRFENT' AND ent.sigdep != 'DPT3' LEFT OUTER JOIN eve ret ON ret.codsoc = fct_mev(msk.codsoc, 'EVE', ' ') AND ret.achvte = msk.achvte AND ret.typeve = msk.typeve AND ret.numeve = msk.numeve LEFT OUTER JOIN evp retp ON retp.codsoc = fct_mev(ret.codsoc, 'EVP', ' ') AND retp.achvte = ret.achvte AND retp.typeve = ret.typeve AND retp.numeve = ret.numeve AND retp.numpos = msk.poseve LEFT OUTER JOIN evt rettn ON rettn.codsoc = fct_mev(ret.codsoc, 'EVT', ' ') AND rettn.achvte = retp.achvte AND rettn.typeve = retp.typeve AND rettn.numeve = retp.numeve AND rettn.numpos = retp.numpos WHERE mev.codent = 'MEV' AND mev.segment = ' ' AND msk.sigdep = 'DPT3' AND msk.codosk IN ('SORTIE', 'ENTREE', 'TRFSOR', 'TRFENT', 'INICPT', 'INIT', 'VREAVN', 'VLIVVN') AND tsc.datdeb = ( SELECT max(datdeb) FROM tsc tsc2 WHERE tsc2.codsoc = tsc.codsoc AND tsc2.achvte = tsc.achvte AND tsc2.codpro = tsc.codpro AND tsc2.prxtar = ( SELECT max(prxtar) FROM tsc tsc3 WHERE tsc3.codsoc = tsc2.codsoc AND tsc3.achvte = tsc2.achvte AND tsc3.codpro = tsc2.codpro ) ) GROUP BY mev.codsoc, msk.nummsk, msk.codpro, pro.fampro, pro.sfapro, pro.ssfpro, pro.nompro, msk.datmvt, msk.typosk, msk.codosk, msk.achvte, msk.typeve, msk.numeve, msk.qteope, msk.prxvte, msk.prxrev, tsc.prxtar, ret.typtie, ret.sigtie, ret.refext, rettn.commen1, rettn.commen2, rettn.commen3, rettn.commen4, ent.sigdep
|
|