Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Complicated SQL - can we make it?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00437328
Message ID:
00437410
Views:
28
>Hi Nadya,
>
>I think i have found it.
>Just a simple thought, but it looks like it works with two different sql statements.
>The first is the same like you said.
>(I created something alike to test)
>
>* Sample data
>Jaar=Year
>Maand=Month
>Bedrag=Amount
>table1 && same as first select
>Jaar Maand
>1999 01
>2000 01
>2000 02
>2000 04
>
>Table2 && original table
>Jaar Maand Bedrag
>2000 01 10
>2000 01 10
>2000 04 40
>1999 01 1
>2000 04 40
>2000 02 20
>
>SQL
>
>select table1.maand,table1.jaar,table1.maand+table1.jaar,sum(table2.bedrag);
>from table1,table2;
>where table2.jaar=table1.jaar and table2.maand between '01' and table1.maand;
>group by 3
>
>
>Output:
>Month Year Dummy Tot_Amount
>01 1999 011999 1
>01 2000 012000 20
>02 2000 022000 42
>04 2000 042000 122

Forgat including count(*) but that does work too
Month Year Dummy Tot_Amount Count
01 1999 011999 1 1
01 2000 012000 20 2
02 2000 022000 42 3
04 2000 042000 122 5

For the quaters you have to do the same.
So in total 4 simple querys.
Probably someone who knows more about SQL than me, can convert this into two statements.

PS. the between function is replaced by the SQL equivalent.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform