【发布时间】:2021-03-29 07:19:16
【问题描述】:
表 1 (aws_complianceitem) 没有主键,此示例数据:
| status | severity | compliancetype | title | resourceid | region |
|---|---|---|---|---|---|
| compliant | low | security | 2002 patch | i-76765434 | ap-south-2 |
| noncompliant | high | audit | 2002 kb patch | i-76765434 | ap-south-2 |
| compliant | medium | security | 2002 kb patch | i-98765434 | ap-south-1 |
表 2 (aws_instanceinformation) 具有 ipaddress 和 instanceid 作为唯一键,并具有以下示例数据:
| computername | instanceid | ipaddress | status | accountid |
|---|---|---|---|---|
| SD-SDYH-re22 | i-76765434 | 10.33.23.1 | complianed | 887878787654 |
| noncompliant | i-98765434 | 10.72.33.1 | non-complianed | 098776765478 |
表 3 (configinstancestate) 具有 ipaddress 和 resourceid 作为唯一键和此示例数据:
| resourceid | ipaddress | instancestate |
|---|---|---|
| i-76765434 | 10.33.23.1 | running |
| i-98765434 | 10.72.33.1 | stopped |
我需要所有正在运行的 instanceid 的数据。
这是想要的结果:
| status | instancestate | severity | title | resourceid | region | ipaddress |
|---|---|---|---|---|---|---|
| compliant | running | low | 2002 patch | i-76765434 | ap-south-2 | 10.33.23.1 |
| noncompliant | running | high | 2002 kb patch | i-76765434 | ap-south-2 | 10.33.23.1 |
| compliant | stopped | medium | 2002 kb patch | i-98765434 | ap-south-1 | 10.72.33.1 |
尝试使用以下查询的完全外连接,
SELECT
t1.status
, t1.severity
, t1.title
, t1.region
, t1.resourceid
, t2.ipaddress
, t2.computername
, t2.status
, t3.instancestate
FROM
aws_complianceitem t1
FULL OUTER JOIN aws_instanceinformation t2
ON t1.resourceid = t2.instanceid
FULL OUTER JOIN configinstancestate t3
ON t2.ipaddress = t3.resourceid
但是我们过滤了这个结果,我们作为这个查询的一部分使用 instancestate=blank,有空记录
【问题讨论】:
标签: sql amazon-web-services inner-join presto amazon-athena