简体   繁体   English

Oracle SQL Developer中的SQL查询

[英]SQL Query in Oracle SQL Developer

I have four tables that I want to join and display the output all together. 我有四个表要加入并一起显示输出。 I'm not sure how the syntax works for Oracle SQL Developer. 我不确定语法对Oracle SQL Developer的作用。 I know this is an easy question for a programmer and I was hoping someone can make a suggestion on how the code might look like. 我知道对于程序员来说这是一个简单的问题,我希望有人可以就代码的外观提出建议。

The tables are tables are: JNL1 JNL2 JNL3 JNL4 表格是:JNL1 JNL2 JNL3 JNL4

JNL1
JNL2
JNL3
JNL4

I only want to display the results with UserCode=Automation and the Date to be one day before the current one. 我只希望用UserCode = Automation显示结果,并将Date设置为当前的一天。 The code for that is: 代码是:

  UserCode = 'Automation' AND     
  CONVERT(VARCHAR,LEFT(DATE,8))=CONVERT(VARCHAR(8),GETDATE()-1,112)

The keys that are common between all four of these tables is ItemID, Date, and UserCode. 所有这四个表之间共有的键是ItemID,Date和UserCode。

I'm not sure how the query will look like, I can generate the joining tables query and the UserCode/Date query as separate queries. 我不确定查询的样子,我可以生成连接表查询和UserCode / Date查询作为单独的查询。 But when I combine them into one query I either get errors on ambiguous column name, or the query runs with no data being displayed from the database. 但是当我将它们组合成一个查询时,我或者在模糊列名称上得到错误,或者运行查询而没有从数据库中显示数据。

Don't join the tables. 不要加入表格。 as you require to get the data from only one table and table structure are same then you can have multiple unions 因为您只需要从一个表和表结构获取数据,所以您可以拥有多个unions

-- In oracle database you can not have column name as date, I am assuming that date column name is c_date- - 在oracle数据库中,你不能将列名作为日期,我假设date列名是c_date-

select ItemID, c_Date, and UserCode
from Jul1
where UserCode = 'Automation' 
  AND c_date = trunc(sysdate) -1
union all 
select ItemID, c_Date, and UserCode
from Jul2
where UserCode = 'Automation' 
  AND c_date = trunc(sysdate) -1
union all 
select ItemID, c_Date, and UserCode
from Jul3
where UserCode = 'Automation' 
  AND c_date = trunc(sysdate) -1
union all 
select ItemID, c_Date, and UserCode
from Jul4
where UserCode = 'Automation' 
  AND c_date = trunc(sysdate) -1

* sysdate is system function which will return the current date with time value. * sysdate是系统函数,它将返回当前日期和时间值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM