[英]SQL Query in Oracle SQL Developer
我有四个表要加入并一起显示输出。 我不确定语法对Oracle SQL Developer的作用。 我知道对于程序员来说这是一个简单的问题,我希望有人可以就代码的外观提出建议。
表格是:JNL1 JNL2 JNL3 JNL4
JNL1
JNL2
JNL3
JNL4
我只希望用UserCode = Automation显示结果,并将Date设置为当前的一天。 代码是:
UserCode = 'Automation' AND
CONVERT(VARCHAR,LEFT(DATE,8))=CONVERT(VARCHAR(8),GETDATE()-1,112)
所有这四个表之间共有的键是ItemID,Date和UserCode。
我不确定查询的样子,我可以生成连接表查询和UserCode / Date查询作为单独的查询。 但是当我将它们组合成一个查询时,我或者在模糊列名称上得到错误,或者运行查询而没有从数据库中显示数据。
不要加入表格。 因为您只需要从一个表和表结构获取数据,所以您可以拥有多个unions
- 在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
是系统函数,它将返回当前日期和时间值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.