Oracle数据库查询调整

发布于 2025-02-10 03:36:23 字数 361 浏览 1 评论 0原文

我有一个很大的SQL查询,并且难以管理,我需要的帮助IFI可以做任何事情 -

将内部查询存储在变量中,并在外部查询中使用变量作为参考示例示例

var1 = select * from customer
var2 = select * from product
var3= select custid from var1

and finally

select a.customername,b*,c* from var1 as a, var2 as b , var3 as c  where a.custid = c.c_id and     
a.custid = b.custid 

注意我不是数据库人员,我是Java程序员

I have a big sql query and its difficult to manage, what I need help ifI can do anything like -

store the inner queries in variables and use variable as reference in the outer queries example

var1 = select * from customer
var2 = select * from product
var3= select custid from var1

and finally

select a.customername,b*,c* from var1 as a, var2 as b , var3 as c  where a.custid = c.c_id and     
a.custid = b.custid 

Note I am not a database person, I am a java programmer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘初心 2025-02-17 03:36:23

您可以使用CTE(常见表表达式)来简化主查询。例如,您的查询可以改写为:

with
a as (
  -- big complex query #1 here
),
b as (
  -- big complex query #2 here
),
c as (
  -- big complex query #3 here
)
select a.customername, b.*, c.* -- the main query starts at this line
from a
join b on b.custid = a.custid
join c on c.c_id = a.custid

主要查询可以参考任何CTE(abc)) 。每个CTE都可以提及先前定义的CTE。在您的示例中,第三个可能会引用第一个。

You can use CTEs (Common Table Expressions) to simplify the main query. For example, your query can be rephrased as:

with
a as (
  -- big complex query #1 here
),
b as (
  -- big complex query #2 here
),
c as (
  -- big complex query #3 here
)
select a.customername, b.*, c.* -- the main query starts at this line
from a
join b on b.custid = a.custid
join c on c.c_id = a.custid

The main query can have references to any of the CTEs (a, b, or c). Each CTE can alse have references to the previously defined CTEs; in your example, the third one will probably reference the first one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文