【发布时间】:2020-12-20 22:31:30
【问题描述】:
对于下面提到的表说 datarate_tbl,我需要自联接方面的帮助
我需要比较两个日期的数据,例如同一张表中的 18 日和 20 日。 我需要查询数据以从同一个表中提取数据,以便将 file_size 和 rate 列的数据与第 18 个数据对齐
查询到的数据应该是这样的
我尝试使用自联接编写查询,但努力获取结果数据集。希望有任何帮助
我的查询给了我额外的两行而不是 5 行。问题发生在网络并行处。
select a.date::date ,a.hostname,a.test_type,a.file_size,a.rate ,b.date::date ,b.file_size ,b.rate
from checkperf_allproduct_metrics a
left join(select * from checkperf_allproduct_metrics where date::date = '2020-12-18') b
on a.instance = b.instance
and a.hostname=b.hostname
and a.test_type =b.test_type
where a.instance = 'nytpsg00394'
and a.date::date = '2020-12-20'
;
date | hostname | test_type | file_size | rate | date | file_size | rate
------------+--------------------------------------------------------+--------------+------------+-------------+------------+------------+-------------
2020-12-20 | abc.com.in | disk write | 1073741824 | 297.67 | 2020-12-18 | 1073741824 | 344.78
2020-12-20 | abc.com.in | disk read | 1073741824 | 3413.33 | 2020-12-18 | 1073741824 | 2438.10
2020-12-20 | abc.com.in | stream | 0 | 15887.52 | 2020-12-18 | 1073741824 | 15116.31
2020-12-20 | abc.com.in-> abc.com.in| Net Parallel | | 3187.470000 | 2020-12-18 | 1073741824 | 3285.460000
2020-12-20 | abc.com.in-> abc.com.in| Net Parallel | | 3187.470000 | 2020-12-18 | 1073741824 | 3215.270000
2020-12-20 | abc.com.in-> abc.com.in| Net Parallel | | 3163.380000 | 2020-12-18 | 1073741824 | 3285.460000
2020-12-20 | abc.com.in-> abc.com.in| Net Parallel | | 3163.380000 | 2020-12-18 | 1073741824 | 3215.270000
问题实际上发生在 Net Parallel 列中。如果你能帮我解决这个问题。
【问题讨论】:
标签: sql postgresql pivot inner-join self-join