英文:
how to combine results of query of multiple rows into one row
问题
Here's the translated query:
我有这个查询的结果。
select distinct "CVE_ID","V19_200","V20","V20_100","V21","V21_100","V21_200"
from cve_table
where "CVE_ID"='CVE-2022-22965';
我想要的是这样的。
CVE_ID | V19_200 | V20 | V20_100 | V21 | V21_100 | V21_200
----------------|---------|-----|---------|-----|---------|---------
CVE-2022-22965 | t | t | t | t | t | f
我尝试过使用`UNION`和`UNION ALL`,但对我来说没有起作用,或者我没有找到正确的方法。
Please note that the translated SQL code retains the code parts and format from your original query.
英文:
I have this results from this query.
select distinct "CVE_ID","V19_200","V20","V20_100","V21","V21_100","V21_200"
from cve_table
where "CVE_ID"='CVE-2022-22965';
CVE_ID | V19_200 | V20 | V20_100 | V21 | V21_100 | V21_200 |
---|---|---|---|---|---|---|
CVE-2022-22965 | f | f | f | f | f | f |
CVE-2022-22965 | f | f | f | f | t | f |
CVE-2022-22965 | f | f | f | t | f | f |
CVE-2022-22965 | f | f | t | f | f | f |
CVE-2022-22965 | f | t | f | f | f | f |
CVE-2022-22965 | t | f | f | f | f | f |
What I want is this.
CVE_ID | V19_200 | V20 | V20_100 | V21 | V21_100 | V21_200 |
---|---|---|---|---|---|---|
CVE-2022-22965 | t | t | t | t | t | f |
I have tried to UNION
and UNION ALL
but it didn't work for me or I couldn't do it the right way.
答案1
得分: 2
使用BOOL_OR
和GROUP BY
如下所示:
SELECT "CVE_ID",
BOOL_OR("V19_200") as "V19_200",
BOOL_OR("V20") as "V20",
BOOL_OR("V20_100") as "V20_100",
BOOL_OR("V21") as "V21",
BOOL_OR("V21_100") as "V21_100",
BOOL_OR("V21_200") as "V21_200"
FROM cve_table
WHERE "CVE_ID" = 'CVE-2022-22965'
GROUP BY "CVE_ID";
英文:
Use BOOL_OR
and GROUP BY
as follows:
SELECT "CVE_ID",
BOOL_OR("V19_200") as "V19_200",
BOOL_OR("V20") as "V20",
BOOL_OR("V20_100") as "V20_100",
BOOL_OR("V21") as "V21",
BOOL_OR("V21_100") as "V21_100",
BOOL_OR("V21_200") as "V21_200"
FROM cve_table
WHERE "CVE_ID" = 'CVE-2022-22965'
GROUP BY "CVE_ID";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论