Article View: borland.public.interbase.sql
Article #175Re: How to query
From: willr
Date: Sat, 05 Jul 2008 18:41
Date: Sat, 05 Jul 2008 18:41
36 lines
1999 bytes
1999 bytes
Hs wrote:
> This is my table:
>
> CREATE TABLE "BUY"
> (
> "CUSTOMER_ID" INTEGRER,
> "WEIGHT" INTEGER,
> "BUY_DATE" DATE
> );
>
> I want: SELECT "CUSTOMER_ID", SUM("WEIGHT" * CostA or CostB) TOTAL_COST
> FROM BUY GROUP BY "CUSTOMER_ID";
>
> The problem: I should use CostA when "BUY_DATE" is before 2000/10/10 and CostB when it is after 2000/10/10.
> can I do it in one query? what is the best other way?
>
> Thanks.
I think you have not normalized/designed the table properly. If the cost
can change, it should be tracked at "purchase time".
Purchase time can mean many things... Unfortunately it is not even that
easy as you may have discussed one price with a salesman, been quoted a
different price by an assistant, and received it (or been invoiced at)
at a different price. You might even be dealing with currency exchange.
I suggest that you rethink the problem if you don't want to have a query
with many dates some time in the future. Alternatively you can use a
stored procedure or a view plus a query... But why not solve the
underlying problem?
--
Will R
PMC Consulting
Technical Details
Message-ID:
<486fc066$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<486f7abd$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,19aface1effac68b X-Google-Attributes: gid114a0e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Sat, 05 Jul 2008 12:41:47 -0600 From: willr <willr@pmccl.com> User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: How to query References: <486f7abd$1@newsgroups.borland.com> In-Reply-To: <486f7abd$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 189.174.176.59 Message-ID: <486fc066$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1215283302 189.174.176.59 (5 Jul 2008 11:41:42 -0700) Lines: 36 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!news.isoc.lu!newsgroups.borland.com!not-for-mail