开发者

SQL combine SELECT statements into two columns

TWO Tables SQL 2005 Tables

   Trend Table
   Enter  Exit  Number 
   .01    .01     0
   .02    .02     1
   .03    .03     2
   .04    .04     3

  Orders Table
  Ticker    Enter   Exit
   EUR        0        1
   GBP        2        3

Requirement: A single query to produce the Enter and Exit Values from Trend Table given only the Ticker Symbol from the Orders Table.

A Ticker Value will provide Enter and Exit Integers in the Orders Tabl开发者_开发问答e that correspond to the Number Column in The Trend Table which points to the actual Decimal Enter and Exit values that the query should output.

Enter and Exit Values need to be in separate columns. The following query produces output with values in 1 column only (see output)

 SELECT  T.Enter
 FROM Trend AS T INNER JOIN Orders AS O ON O.Enter = T.Number
 WHERE (O.Ticker = 'EUR')
 UNION
 SELECT D.Exit
 FROM Trend AS D INNER JOIN Orders AS F ON F.Exit= D.Number
 WHERE (F.Ticker = 'EUR')

 OUTPUT:
 Exit
 0.01
 0.02


Is this what you are after?

SELECT Orders.Ticker, T1.Enter, T2.Exit
FROM Orders
INNER JOIN Trend T1 ON Orders.Enter = T1.Number
INNER JOIN Trend T2 ON Orders.Exit = T2.Number
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜