Re: compare
From: Louis Davidson (dr_dontspamme_sql_at_hotmail.com)
Date: 12/03/04
- Next message: Steve Kass: "Re: compare"
- Previous message: Louis Davidson: "Re: Why plural table names? (Celko)"
- In reply to: Ed: "compare"
- Next in thread: Steve Kass: "Re: compare"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Dec 2004 23:03:51 -0600
Well, first. Gross. Beyond the question of why you have numbers at the end
of these stores, this is really not a good design. The following would be
the best approach:
Part
===
PartNumber (pkey)
Description
PartPrice
======
PartNumber
Store
Price
(Pkey partNumber, Store)
PartNumber Description
------------ ------------
123 Dunno
CDE Something Else
PartNumber Store Price
------------ ------ ------
123 WalMart 10
123 Target 12
123 HomeDepot 11
CDE WalMart 5
CDE Target 4.5
CDE HomeDepot 5.2
CDE Different 12
Then you could just use Max to get this job done.
However, in the meantime, you can make your solution work:
SELECT PartNumber, WalMart9, Target8, HomeDepot7,
case when WalMart9 <= Target8 and WalMart9 <= HomeDepot7
then WalMart9
when Target8 <= WalMart9 and Target8 <= HomeDepot7
then Target8
else HomeDepot7
end as lowestPrice
I hope for your sake you don't have Walgreens128 :)
-- ---------------------------------------------------------------------------- Louis Davidson - drsql@hotmail.com SQL Server MVP Compass Technology Management - www.compass.net Pro SQL Server 2000 Database Design - http://www.apress.com/book/bookDisplay.html?bID=266 Note: Please reply to the newsgroups only unless you are interested in consulting services. All other replies may be ignored :) "Ed" <Ed@discussions.microsoft.com> wrote in message news:A9D0D592-4DCC-42E0-AC85-C9B95A1FB46E@microsoft.com... > Hi > if i have a table like > PartNumber WalMart9 Target8 HomeDepot7 > 123 $10 $12 $11 > > CDE $5 $4.5 $5.2 > > > is there anyway I could create a colmn called lowest pick the lowest price > for each column... result > PartNumber WalMart9 Target8 HomeDepot7 LowestPrice > 123 $10 $12 $11 > $10 > CDE $5 $4.5 $5.2 > $4.5 > > Thanks > Ed > >
- Next message: Steve Kass: "Re: compare"
- Previous message: Louis Davidson: "Re: Why plural table names? (Celko)"
- In reply to: Ed: "compare"
- Next in thread: Steve Kass: "Re: compare"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|