Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Union Clause and Group by clause
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01141596
Message ID:
01141635
Views:
20
This message has been marked as a message which has helped to the initial question of the thread.
The UNION doesn't do SUM. You have to do it yourself on your query result. IN VFP9 you can use result of your query as derived table and sum it
    SELECT  u1.iemployeeid , ;
    u1.ddate,;
    u1.iplanpauseid , ;
    SUM( u1.totheure ) AS totheure;
    FROM ( <your query here w/o INTO clause > ;
          ) u1 ;
       GROUP BY 1,2,3 ;
    INTO CURSOR temp3
You can also try LEFT JOIN
D_debut = {^2006/06/01}
  d_fin = {^2006/06/30}

SELECT  NVL(h1.iemployeeid, h2.iemployeeid) AS iemployeeid, ;
	    NVL(h1.ddate, ddate) AS ddate,;
    	PAUSE.iplanpauseid , ;
	    SUM( NVL(h1.n100 + h1.n120,0) + NVL(h2.n100_2 + h2.n120_2,0)) AS 'totheure';
    FROM AMLINE!PAUSE ;
    LEFT JOIN AMLINE!Horaire h1 ;
    	ON  PAUSE.iid = h1.cpauseid ;
    		AND h1.ddate BETW  D_debut AND  d_fin ;
    LEFT JOIN AMLINE!h2 ;
     	ON  PAUSE.iid = h2.cpauseid2 ;
    		AND h2.ddate BETW  D_debut AND  d_fin ;
    GROUP BY 1 , 2 , 3 ;
    HAVING iemployeeid IS NOT NULL ;
    INTO CURSOR temp3
MAybe I missing somethin but I don't se why you need UNION
>
>I Have Horaire.dbf
>iemployeeid I
>ipauseid I
>ipauseid2 I
>ddate D
>n100     N(8,2)
>n120     n(8,2)
>n100_2   N(8,2)
>n120_2   N(8,2)
>
>I want the sum of n100 + n120 + n100_2 n120_2 per each iemployeeid , ddate , iplanpauseid
>
><PRE>
>
> D_debut = {^2006/06/01}
>  d_fin = {^2006/06/30}
>
>SELECT  Horaire.iemployeeid , ;
>    Horaire.ddate,;
>    PAUSE.iplanpauseid , ;
>    SUM( Horaire.n100 + Horaire.n120 ) AS 'totheure';
>    FROM AMLINE!PAUSE ;
>    INNER JOIN AMLINE!Horaire  	ON  PAUSE.iid = Horaire.cpauseid ;
>    WHERE Horaire.ddate BETW  D_debut AND  d_fin ;
>    GROUP BY 1 , 2 , 3 ;
>       UNION ;
>    SELECT  Horaire.iemployeeid , ;
>    Horaire.ddate,;
>    PAUSE.iplanpauseid , ;
>    SUM( Horaire.n100_2 + Horaire.n120_2 ) AS 'totheure';
>    FROM AMLINE!PAUSE ;
>    INNER JOIN AMLINE!Horaire  	ON  PAUSE.iid = Horaire.cpauseid2 ;
>    WHERE Horaire.ddate BETW  D_debut AND  d_fin ;
>       GROUP BY 1,2,3 ;
>    INTO CURSOR temp3
>
>
>
>This result is bad because itis not group by on 01/06/2006 ...???
>
>http://www.amline.be/Ng/union.jpg
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform