I have a problem:
I am riding a select that brings me the total sales of a certain business day.
Well,
I created a view that brings me all the business days of the month by discounting the holidays registered in Tsifer. (I needed to do for the year, but for now the month serves me)
This table I use as helper in case there is no sale in the day And also to generate the table of the integer, so that it can follow according to the daily selling target of the seller as much as it lacks it to reach the daily goal. The totalizers in the software I use are mounted on the report view.
Also to make it easier I created another view that rides presents the Meta's X Meta sales for all sellers.
CREATE OR REPLACE VIEW VENDA_DIARIA AS
SELECT DISTINCT
VEN.CODVEND, VEN.APELIDO, FDU.DATA AS DTNEG
/*CAB.DTNEG*/,
CASE WHEN (TRUNC(FDU.DATA) = TRUNC(CAB.DTNEG)) THEN SUM(CAB.VLRNOTA) ELSE 0 END AS VENDAS,
MET.DTREF,
(MET.PREVREC / (SELECT COUNT(DATA) FROM FOCA_DIAS_UTEIS WHERE TO_CHAR(DATA, 'MM') = TO_CHAR(MET.DTREF, 'MM'))) METADIARIA
FROM TGFCAB CAB
LEFT JOIN TGFITE ITE ON ITE.SEQUENCIA = 1 AND ITE.NUNOTA = CAB.NUNOTA
LEFT JOIN TGFVEN VEN ON VEN.CODVEND = ITE.CODVEND
LEFT JOIN TGMMET MET ON MET.CODVEND = VEN.CODVEND
LEFT JOIN DIAS_UTEIS FDU ON FDU.DATA <> TO_DATE('01/01/2001')
WHERE CAB.TIPMOV = 'P' AND CAB.SERIENOTA = 'P'
AND CAB.DTNEG BETWEEN MET.DTREF AND LAST_DAY(MET.DTREF)
GROUP BY VEN.CODVEND, VEN.APELIDO, FDU.DATA,
CAB.DTNEG, MET.DTREF, MET.PREVREC
>
>
>
SQL> SELECT * FROM VENDA_DIARIA WHERE CODVEND = 3;
CODVEND APELIDO DTNEG VENDAS DTREF METADIARIA
------- --------------- ----------- ---------- ----------- ----------
3 ALTAIR 01/11/2010 0 01/11/2010 3150
3 ALTAIR 01/11/2010 4025,52 01/11/2010 3150
3 ALTAIR 03/11/2010 0 01/11/2010 3150
3 ALTAIR 03/11/2010 3804,1 01/11/2010 3150
3 ALTAIR 04/11/2010 0 01/11/2010 3150
3 ALTAIR 04/11/2010 2909,33 01/11/2010 3150
3 ALTAIR 05/11/2010 0 01/11/2010 3150
3 ALTAIR 05/11/2010 5052,74 01/11/2010 3150
3 ALTAIR 08/11/2010 0 01/11/2010 3150
3 ALTAIR 09/11/2010 0 01/11/2010 3150
3 ALTAIR 10/11/2010 0 01/11/2010 3150
3 ALTAIR 11/11/2010 0 01/11/2010 3150
3 ALTAIR 12/11/2010 0 01/11/2010 3150
3 ALTAIR 16/11/2010 0 01/11/2010 3150
3 ALTAIR 17/11/2010 0 01/11/2010 3150
3 ALTAIR 18/11/2010 0 01/11/2010 3150
3 ALTAIR 19/11/2010 0 01/11/2010 3150
3 ALTAIR 22/11/2010 0 01/11/2010 3150
3 ALTAIR 23/11/2010 0 01/11/2010 3150
3 ALTAIR 24/11/2010 0 01/11/2010 3150
3 ALTAIR 25/11/2010 0 01/11/2010 3150
3 ALTAIR 26/11/2010 0 01/11/2010 3150
3 ALTAIR 29/11/2010 0 01/11/2010 3150
3 ALTAIR 30/11/2010 0 01/11/2010 3150
24 rows selected
Can anyone help me?
: -O
Valeu