Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Union and Group by clause
Message
From
27/03/2010 14:30:53
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01457617
Message ID:
01457624
Views:
52
This message has been marked as a message which has helped to the initial question of the thread.
>Hi all,
>
>i want a single sql command .
>I WANT count a field of 2 tables with union clause
>
>I want 2 for result of ncount() && {^2009/10/01}
>
>
> m.d_debut = {^2009/10/01}
>
>  CREATE CURSOR Temp1 ( Ch1 D(8) )
>
>  INSERT INTO Temp1  VALUE( m.d_debut )
>  INSERT INTO Temp1  VALUE(m.d_debut + 1 )
>  INSERT INTO Temp1  VALUE(m.d_debut + 2 )
>  INSERT INTO Temp1  VALUE(m.d_debut + 3 )
>
>
>  CREATE CURSOR Temp2 ( Ch1 D(8) )
>  INSERT INTO Temp2  VALUE( m.d_debut )
>
>  SET ENGINEBEHAVIOR 90
>  SELECT Temp1.Ch1 ,;
>    COUNT(Temp1.Ch1) AS NCOUNT  GROUP BY 1 FROM Temp1;
>    UNION;
>    SELECT Temp2.Ch1,;
>    COUNT(Temp2.Ch1) AS NCOUNT  FROM Temp2;
>    GROUP BY 1 INTO CURSOR temp
>
>
>
>The result is bad...
	d_debut = {^2009/10/01}

  CREATE CURSOR Temp1 ( Ch1 D(8) )

  INSERT INTO Temp1  VALUE( m.d_debut )
  INSERT INTO Temp1  VALUE(m.d_debut + 1 )
  INSERT INTO Temp1  VALUE(m.d_debut + 2 )
  INSERT INTO Temp1  VALUE(m.d_debut + 3 )


  CREATE CURSOR Temp2 ( Ch1 D(8) )
  INSERT INTO Temp2  VALUE( m.d_debut )

  SET ENGINEBEHAVIOR 90
  select ch1, ;
  	sum(ncount) as nCount ;
  	from ( ;
		  SELECT	Temp1.Ch1 ,;
		    	COUNT(Temp1.Ch1) AS NCOUNT  ;
		    FROM Temp1 ;
		    GROUP BY 1 ;
		    UNION all ;
		  SELECT	Temp2.Ch1,;
	   		COUNT(Temp2.Ch1) AS NCOUNT ;
	   	FROM Temp2;
   		GROUP BY 1 ;
   	) X ;
   	group by 1 ;
   	INTO CURSOR temp
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform