与从 2 个不为空的表中获取数据相关的数据库查询

Posted

技术标签:

【中文标题】与从 2 个不为空的表中获取数据相关的数据库查询【英文标题】:DB Query related to get data from 2 tables which are not null 【发布时间】:2017-12-01 11:38:48 【问题描述】:
select FCPDD.AUDIENCE_ID,FCPD.APPLICATION_RULE_ID,FCPD.PROGRAMME_PART,FCPD.TARGET_DATE,FCPD.TIMEBAND_START_TIME,
FCPD.TIMEBAND_END_TIME,FCPD.DAY_NUMBER
FROM FPR_CHANNEL_PROCESS_DATA FCPD,FPR_CHANNEL_PROCESS_DATA_DTL FCPDD 
WHERE FCPD.CHANNEL_PROCESS_DATA_ID=FCPDD.CHANNEL_PROCESS_DATA_ID and FCPD.TARGET_DATE is not null and FCPDD.AUDIENCE_ID is not null 
and FCPD.APPLICATION_RULE_ID is not null and FCPD.PROGRAMME_PART is not null and FCPD.TIMEBAND_START_TIME is not null
and FCPD.TIMEBAND_END_TIME is not null and FCPD.DAY_NUMBER is not null 

我们可以把上面的查询写成精确的形式吗

【问题讨论】:

【参考方案1】:

参考链接: Using IS NOT NULL for multiple columns

试试这个,

SELECT FCPDD.AUDIENCE_ID,FCPD.APPLICATION_RULE_ID,FCPD.PROGRAMME_PART,FCPD.TARGET_DATE,FCPD.TIMEBAND_START_TIME,
FCPD.TIMEBAND_END_TIME,FCPD.DAY_NUMBER
FROM FPR_CHANNEL_PROCESS_DATA FCPD,FPR_CHANNEL_PROCESS_DATA_DTL FCPDD 
WHERE FCPD.CHANNEL_PROCESS_DATA_ID=FCPDD.CHANNEL_PROCESS_DATA_ID AND 
NOT(FCPD.TARGET_DATE IS NULL 
OR FCPDD.AUDIENCE_ID IS NULL 
OR FCPD.APPLICATION_RULE_ID IS NULL 
OR FCPD.PROGRAMME_PART IS NULL 
OR FCPD.TIMEBAND_START_TIME IS NULL
OR FCPD.TIMEBAND_END_TIME IS NULL 
OR FCPD.DAY_NUMBER IS NULL )

试试这个:

SELECT FCPDD.AUDIENCE_ID,FCPD.APPLICATION_RULE_ID,FCPD.PROGRAMME_PART,FCPD.TARGET_DATE,FCPD.TIMEBAND_START_TIME,
FCPD.TIMEBAND_END_TIME,FCPD.DAY_NUMBER
FROM FPR_CHANNEL_PROCESS_DATA FCPD,FPR_CHANNEL_PROCESS_DATA_DTL FCPDD 
WHERE (FCPD.CHANNEL_PROCESS_DATA_ID=FCPDD.CHANNEL_PROCESS_DATA_ID AND 
NOT(FCPD.TARGET_DATE IS NULL 
OR FCPDD.AUDIENCE_ID IS NULL 
OR FCPD.APPLICATION_RULE_ID IS NULL 
OR FCPD.PROGRAMME_PART IS NULL 
OR FCPD.TIMEBAND_START_TIME IS NULL
OR FCPD.TIMEBAND_END_TIME IS NULL 
OR FCPD.DAY_NUMBER IS NULL ))

【讨论】:

错误如下:ORA-00907:缺少右括号 00907. 00000 -“缺少右括号” *原因:*操作:第 9 列错误:22 remove 结尾不为空,添加在 where 子句之后和条件中

以上是关于与从 2 个不为空的表中获取数据相关的数据库查询的主要内容,如果未能解决你的问题,请参考以下文章

如何在mysql中获取值不为null的列名

对 laravel 的查询以从“已填充”且不为空的 db 行中获取百分比

R:获取值不为空的列名

Oracle中查询某字段不为空的SQL语句怎么写

sql 语句 查询 为空的

sql查询不为空的字段