🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #207

Re: need advice about sql for data mining

#207
From: Isaac
Date: Tue, 10 Jun 2008 16:56
57 lines
2285 bytes
Maxim Shiryaev wrote:
> Hi.
>
> I think you need a SP here.
>
> for
>   select date
>     from purchase
>
>     union all
>
>     select date
>     from sales
>
>     group by 1
>   into :d
>   /* now you have all the dates here */
> do begin
>
>   select sum(purchase_line.qty), sum(purchase_line.price *
> purchase_line.qty),
>   from purchase
>     left join purchase_line on purchase_line.purchase_id =
> purchase.purchase_id
>   where
>     purchase.date = :d
>   into :purchase_qty, :purchase_amount;
>
>   select sum(sales_line.qty), sum(sales_line.price * sales_line.qty)
>   from sales
>     left join sales_line on purchase_line.sales_id = sales.sales_id
>   where
>     sales.date = :d
>   into :sales_qty, :sales_amount;
>
>   /* be prepared to deal with NULLs in qty and amount here */
>
>   /* calculate whatever needed */
>
> end
>
> And I would even combine both purchases and sales into single table with one
> additional field like SIGN with +1 | -1 values to differentioate between two
> types of operations. So you can create an index on date and get fast GROUP
> BY speed. If so you could make the result in one pass ordering by dates and
> summing appropiate variable depending on sign.
>
>
> Maxim.
>
>
>
>   
>
>
>   
Thanks , but I did not understand how I can make the sign field
Technical Details
Message-ID: <484eb194@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <484db5e2@newsgroups.borland.com> <484e2f00$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,b4be59b23378bfae
X-Google-Attributes: gid114a0e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 10 Jun 2008 19:56:40 +0300
From: Isaac <no@no.com>
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
MIME-Version: 1.0
Newsgroups: borland.public.interbase.sql
Subject: Re: need advice about sql for data mining 
References: <484db5e2@newsgroups.borland.com> <484e2f00$1@newsgroups.borland.com>
In-Reply-To: <484e2f00$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 41.234.200.177
Message-ID: <484eb194@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1213116820 41.234.200.177 (10 Jun 2008 09:53:40 -0700)
Lines: 57
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail