oracle 将查询值与另一个表中的多项选择相乘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8307101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:28:12 来源:igfitidea点击:
Multiplying a query value with multiple select from another table
提问by Aks
I have two tables A and B
我有两个表 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
I need to do a
我需要做一个
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'
I need to fetch the three factors from Table B and do the multiplication. How do I do the multiplication with multiple values from another table after matching the date?
我需要从表 B 中获取三个因子并进行乘法运算。匹配日期后,如何与另一个表中的多个值进行乘法运算?
回答by Marco
Try this:
尝试这个:
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'