1、 个人基本表GRJBB   
(   
  BZH varchar2( 16 ), /* 保障号 */
  XM varchar2( 8 ) not null, /* 姓名 */
  CZLB number( 1) not null, /* 类别 */

 2、个人缴费表grjfb   
 (   
  BZH varchar2( 16 ), /* 保障号 */
  ND varchar2( 4 ) not null, /* 年度 */
  GZLJ1 number( 6 ), /* 工资累计1*/   
  GZLJ2 number( 6 ), /* 工资累计2*/   
  )   
3、缴费明表jfmxb
(   
  BZH varchar2( 16 ), /* 保障号 */
  ND varchar2( 4 ) not null, /* 年度 */
  JFGZ1 number( 4 ), /* 缴费工资1 */   
  dzrq1 string /*到账日期1*/  JFGZ2 number( 4 ), /* 缴费工资2 */
  dzrq1 string /*到账日期2*/  .............................
  JFGZ12 number( 4 ), /* 缴费工资12 */
  dzrq12 string /*到账日期12*/  )我要按年代排序查询出缴费表和明细表的上下半年的错误数据,GZLJ1<>JFGZ1+JFGZ2+JFGZ3+JFGZ4+JFGZ5+JFGZ6
语句是这样写的,也查出正确数据了select a.bzh as 保障号,a.ztw as 状态,a.czlb as 财政类别, b.nd as 年代,b.GZLJ1 as 缴费表上半年,c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6 as 详细上半年
from grjbb as a,grjfb as b,jfmxb as c
where a.bzh=b.bzh and a.bzh=c.bzh   
and a.czlb=2   
and b.nd=c.nd
and b.GZLJ1<>c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6
但是现在需要多加一个条件筛选,就是凡是‘到账日期’是空的或者是‘注销’的,全部不要
如何添加条件呢?

解决方案 »

  1.   

    一个哥们说加上这个 
    and (dzrq1 is not null or dzrq1 ='注销')and (dzrq2 is not null or dzrq2 ='注销').....
    但是查询出来的 结果还是有把注销状态的金额加进去了
      

  2.   

    and (dzrq1 is not null or dzrq1 ='注销')or(dzrq2 is not null or dzrq2 ='注销')or.....
      

  3.   

    and ((dzrq1 is not null or dzrq1 ='注销')or(dzrq2 is not null or dzrq2 ='注销')or.....
    )
      

  4.   

    凡是‘到账日期’是空的或者是‘注销’的都不计算,不是不查询出来
    比如gzlj1=20,dzrq1='19990102'gzlj2=20,dzrq2='注销'
    就是要c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6 as 详细上半年 要等于20
      

  5.   

    我需要查询出b表的GZLJ1与C表的JFGZ1、JFGZ2、JFGZ3、JFGZ4、JFGZ5、JFGZ6的和不一致的数据
    比如所以我就这样写b.gzlj1<>JFGZ1+JFGZ2+JFGZ3+JFGZ4+JFGZ5+JFGZ6但是要排除一个条件就是当jfgz1后面的字段dzrq1为空或者‘注销’的时候,这个jggz1就不累计
    比如gzlj1=20,dzrq1='19990102'
        gzlj2=20,dzrq2='注销'
        gzlj3=20,dzrq3='19980201'
    我要累计成40,注销的那个gzlj2就不累计
      

  6.   

    我之前这样写,但是不正确
    select a.bzh as 保障号,a.ztw as 状态,a.czlb as 财政类别,b.gzlj1,b.gzlj2, b.nd as 年代,b.GZLJ1 as 缴费表上半年,c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6  as 明细表上半年
    from grjbb a,grjfb b,jfmxb  c 
    where b.bzh=a.bzh and c.bzh=a.bzh and c.bzh=b.bzh  
    and b.nd=c.nd 
    and b.GZLJ1<>c.JFGZ1+c.JFGZ2+c.JFGZ3+c.JFGZ4+c.JFGZ5+c.JFGZ6 and (dzrq1 is not null or dzrq1 <>'注销') and (dzrq2 is not null or dzrq2 <>'注销')and (dzrq3 is not null or dzrq3 <>'注销')  
    and (dzrq4 is not null or dzrq4 <>'注销') and (dzrq5 is not null or dzrq5 <>'注销')and (dzrq6 is not null or dzrq6 <>'注销')  
    and (dzrq7 is not null or dzrq7 <>'注销') and (dzrq8 is not null or dzrq8 <>'注销')and (dzrq9 is not null or dzrq9 <>'注销')  
    and (dzrq10 is not null or dzrq10 <>'注销') and (dzrq11 is not null or dzrq11 <>'注销')and (dzrq12 is not null or dzrq12 <>'注销')  
    order by b.nd