将查询值与另一个表中的多个select相乘

时间:2011-11-29 07:11:15

标签: sql oracle

我有两张桌子A和B

Table A
Name  Time               Price
a     12/01/2011 12:01   1.2
a     12/01/2011 12:02   1.3     
a     12/01/2011 12:03   1.7  

Table B
Name   Date        Factor_P  Factor_Q  Factor_R
a      12/01/2011  0.234     1.456     1.445
a      12/02/2011  0.345     1.222     1.765

我需要做一个

Select Price * (Factor_P * Factor_Q / Factor_R) from Table A where Name = 'a' and Time > '12/01/2011 09:30' and Time < '12/01/2011 16:00'  

我需要从表B中获取三个因子并进行乘法运算。在匹配日期之后,如何使用另一个表中的多个值进行乘法?

1 个答案:

答案 0 :(得分:2)

试试这个:

SELECT (a.Price * b.Factor_P * b.Factor_Q / b.Factor_R) AS num
FROM tableA a INNER JOIN tableB b
    ON a.Name = b.Name 
   AND TO_CHAR(a.Time, 'DD-MON-YYYY') = TO_CHAR(b.Date, 'DD-MON-YYYY')
WHERE a.Name = 'a'
  AND Time BETWEEN '2011/01/12 09.30.00' AND '2011/01/12 16.00.00'