GreenWizard
Board Regular
- Joined
- Dec 8, 2013
- Messages
- 106
Based on the table below how can I write a SQL Query to Select the Date, Color, AND Corresponding Number (Based on the rules below)
EXAMPLE
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Color[/TD]
[TD]Number1[/TD]
[TD]Number2[/TD]
[TD]Number3[/TD]
[/TR]
[TR]
[TD]1/1[/TD]
[TD]Red[/TD]
[TD]2[/TD]
[TD]5[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]1/2[/TD]
[TD]Blue[/TD]
[TD]7[/TD]
[TD]5[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]1/3[/TD]
[TD]Brown[/TD]
[TD]6[/TD]
[TD]1[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]
IF Color = Red
Then Query Column3 = Number2
If Color = Blue
Then Query Column3 = Number1
If Color = Brown
Then Query Column3 = Number3
If Color = <Anything Other Color>
Then Query Column3 = N/A
EXAMPLE OF DESIRED SQL OUTPUT
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Color[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD]1/2[/TD]
[TD]Blue[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]1/3[/TD]
[TD]Brown[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]1/4[/TD]
[TD]Black[/TD]
[TD]N/A[/TD]
[/TR]
[TR]
[TD]1/1[/TD]
[TD]Red[/TD]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
SQL QUERY CODE: ???
THANKS SO MUCH!!!!!
EXAMPLE
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Color[/TD]
[TD]Number1[/TD]
[TD]Number2[/TD]
[TD]Number3[/TD]
[/TR]
[TR]
[TD]1/1[/TD]
[TD]Red[/TD]
[TD]2[/TD]
[TD]5[/TD]
[TD]9[/TD]
[/TR]
[TR]
[TD]1/2[/TD]
[TD]Blue[/TD]
[TD]7[/TD]
[TD]5[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]1/3[/TD]
[TD]Brown[/TD]
[TD]6[/TD]
[TD]1[/TD]
[TD]4[/TD]
[/TR]
</tbody>[/TABLE]
IF Color = Red
Then Query Column3 = Number2
If Color = Blue
Then Query Column3 = Number1
If Color = Brown
Then Query Column3 = Number3
If Color = <Anything Other Color>
Then Query Column3 = N/A
EXAMPLE OF DESIRED SQL OUTPUT
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Date[/TD]
[TD]Color[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD]1/2[/TD]
[TD]Blue[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]1/3[/TD]
[TD]Brown[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]1/4[/TD]
[TD]Black[/TD]
[TD]N/A[/TD]
[/TR]
[TR]
[TD]1/1[/TD]
[TD]Red[/TD]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]
SQL QUERY CODE: ???
THANKS SO MUCH!!!!!