Oracle中的Corr函数

时间:2018-12-04 20:11:25

标签: oracle correlation

是否可以在Oracle中在两个表的行之间创建关联? 我有两张桌子-一个有温度,另一个有时间在不同城市的湿度。 我想在某些日期之间的给定城市中建立温度与湿度之间的相关性(CORR函数),但是我不确定如何做到这一点。

感谢您的帮助!

desc TEMP;

$.each(json["urls"], function (i) {
     info += "<li><a href='" + this + "'>" + this + "</a></li>";
});

描述湿度;

$.each(json["urls"], function (i, url) {
     info += "<li><a href='" + url + "'>" + url + "</a></li>";
});

我想选择CITY和DATE范围(在某些日期之间)以计算TEMP中的VALUE和HUMIDTY之间的相关性。

1 个答案:

答案 0 :(得分:1)

下面的CTE(带有)用于模拟您的两个表:

var object2 = arr[1];

给我们:

With Temp (City, value, Mdate) as (SELECT 'C1', 19.6, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL 
SELECT 'C3', 10.6, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C3', 12, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 10.1, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 18, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 10, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C1', 21.6, to_date('2017-10-02 20:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C1', 10.6, to_date('2017-10-02 20:01','YYYY-MM-DD HH24:MI') FROM DUAL),

Humidity (City, value, mDate) as (SELECT 'C1', 60, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C3', 70, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C3', 62, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 67, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 68, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C2', 70, to_date('2017-10-02 19:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C1', 71.6, to_date('2017-10-02 20:01','YYYY-MM-DD HH24:MI') FROM DUAL UNION ALL
SELECT 'C1', 70.6, to_date('2017-10-02 20:01','YYYY-MM-DD HH24:MI') FROM DUAL)


--Now this is the query to coorlate the two values between two dates using the two CTE's above. 

SELECT T.City, Corr(T.Value, H.Value)  corr
FROM TEMP T 
INNER JOIN HUMIDITY H 
  on T.City = H.City 
 and T.mDate = H.mDate 
 WHERE T.mDate between to_date('2017-10-01','YYYY-MM-DD') and to_date('2017-11-02','YYYY-MM-DD') 
GROUP BY T.City