甲骨文 -->Postgres 查询

Oracle --gt; Postgres query(甲骨文 --Postgres 查询)
本文介绍了甲骨文 -->Postgres 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名试图将这样的查询转换为 Postgres 的 Oracle 人员.不是很了解所有语法等.希望有人能提供帮助吗?

Oracle 查询:<上一页>选择 c.code、c.recommendation、s.suggested、s.sugg_by、a.approved、a.app_byFROM(选择代码,推荐 FROM 推荐)c,(选择代码,建议,sugg_by FROM 建议) s,(选择代码,已批准,app_by FROM 建议)哪里 c.code = s.code(+)和 c.code = a.code(+);

非常感谢

解决方案

可以尝试使用OUTER JOIN

选择 c.code、c.recommendation、s.suggested、s.sugg_by、a.approved、a.app_byFROM(选择代码,推荐 FROM 推荐)c左连接(选择代码,建议,sugg_by FROM 建议) s on c.code = s.codeLEFT JOIN(选择代码,已批准,app_by FROM 建议)a ON c.code = a.code

您似乎不需要使用子查询,因为您在子查询中没有做任何事情只选择原始列.可以直接查询表.

选择c.代码,c. 推荐,s.建议,s.sugg_by,a.批准,a.app_byFROM 建议 cc.code = s.code 上的 LEFT JOIN 建议LEFT JOIN 建议 a ON c.code = a.code

I'm an Oracle guy trying to convert a query like this to Postgres. Not really understanding all the syntax, etc. Was hoping someone can help?

Oracle Query:

    SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by
    FROM (SELECT code, recommendation FROM recommendations) c,
         (SELECT code, suggested, sugg_by FROM suggestions) s,
         (SELECT code, approved, app_by FROM suggestions) a
    WHERE c.code = s.code(+)
      AND c.code = a.code(+);
    

Much appreciated

解决方案

You can try to use OUTER JOIN

SELECT c.code, c.recommendation, s.suggested, s.sugg_by, a.approved, a.app_by
FROM (SELECT code, recommendation FROM recommendations) c 
LEFT JOIN (SELECT code, suggested, sugg_by FROM suggestions) s on c.code = s.code
LEFT JOIN (SELECT code, approved, app_by FROM suggestions) a ON c.code = a.code

You seem like didn't need to use subquery, because you didn't do anything in the subquery only select original columns. you can query the table directly.

SELECT
    c.code,
    c.recommendation, 
    s.suggested,
    s.sugg_by, 
    a.approved,
    a.app_by
FROM recommendations c 
LEFT JOIN suggestions s on c.code = s.code
LEFT JOIN suggestions a ON c.code = a.code

这篇关于甲骨文 -->Postgres 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)