Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Data Grouping
Message
 
 
To
30/06/2008 17:02:13
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
01327739
Message ID:
01327825
Views:
11
You can do it in a couple of steps. The first one is to group data
* Group data
SELECT NVL(t1.date, t2.date) AS date, NVL(t1.code, t2.code) AS code, SUM(t1.sale_in) AS in, SUM(t2.sale_out) AS out ;
	FROM table1 t1 FULL JOIN table2 t2 ON t1.date = t2.date ;
	GROUP BY 1,2 ;
	ORDER BY 1,2 ;
	INTO CURSOR crsData
The second one could be one of following:
  • CrossTab http://fox.wikis.com/wc.dll?Wiki~CrossTab
  • Dynamically build a query based on previous cursor
  • Some prcedural coding, like SCAN...ENDSCAN, etc.

    >
    > I have two tables table1 and table2 as
    >
    > Create Cursor table1 ;
    > (date d(8),code Char(7),name Char(20), sale_in N(12))
    >
    > Insert Into table1 Values ({^2008-01-15},'1401001','eric',10)
    > Insert Into table1 Values ({^2008-01-15},'1401002','bill',20)
    > Insert Into table1 Values ({^2008-01-16},'1401001','eric',30)
    > Insert Into table1 Values ({^2008-01-17},'1401001','eric',40)
    > Insert Into table1 Values ({^2008-01-18},'1401001','eric',50)
    > Insert Into table1 Values ({^2008-01-17},'1402001','tushar',40)
    > Insert Into table1 Values ({^2008-01-18},'1402003','samir',50)
    >
    > Create Cursor table2;
    > (date d(8),code Char(7),name Char(20), sale_out N(12))
    >
    > Insert Into table2 Values ({^2008-01-15},'1401001','eric',110)
    > Insert Into table2 Values ({^2008-01-15},'1401002','bill',120)
    > Insert Into table2 Values ({^2008-01-16},'1401001','eric',130)
    > Insert Into table2 Values ({^2008-01-17},'1401001','eric',140)
    > Insert Into table2 Values ({^2008-01-18},'1401001','eric',150)
    > Insert Into table2 Values ({^2008-01-17},'1402001','tushar',140)
    > Insert Into table2 Values ({^2008-01-18},'1402003','samir',150)
    >
    >I need folloiwng result
    >
    > -----Date----|------A-----|------B------|
    > ---------------|--In---Out-|--In---Out--|
    > 15-01-2008-|-30---230-|---0------0--|
    > 16-01-2008-|-30---130-|---0------0--|
    > 17-01-2008-|-40---140-|-40---140--|
    > 18-01-2008-|-50---150-|-50---150--|
    >


    > There will be a unique date containing sale_in nd salue_out values against every unique group.
    > every unique group in cross tab will be based on left four characters of code
    > 1401001 will go to A column
    > 1402002 will go to B column
    >
    > IF there is code=1403001 THEN it will be group c and so on.
    >
    > Please help
    --sb--
  • Previous
    Next
    Reply
    Map
    View

    Click here to load this message in the networking platform