Return valuse based on multiple "if exists' conditions (Advanced) -
02-06-2010
, 04:17 PM
Hi All,
Here is a more challenging question derived from my last one in this
thread:
http://groups.google.com/group/comp....6be4865?hl=en#
Here is the table:
state source price
NY A 1
NY B 2
NY C 3
CA B 4
CA C 5
TX C 6
How can I show by state the records that satisfied the following
condition:
if A exists then show only the record where source = A,
if A not exists then see if B exists,
If B exists then show only the record where source = B,
if B not exists then see if C exists,
If C exists then show only the record where source = C,
If none of A, B, C exists, then show '---' for all columns except the
state column.
The result in this example should be:
NY A 1
CA B 4
TX C 6
If there is another record as the following:
MA D 7
then the result will be:
NY A 1
CA B 4
TX C 6
MA --- ---
Please help is anyone knows the answer. Thanks.
SQL Learner |