Select L.BookingID,InvoiceNumber,b.Operator  from 
view_bookingCOSTgroup L   join bookings_new b  
on l.BookingID=b.BookingID  
where ReceivePayTime is NULL and (select count(DocName) from Document where BookingID=l.bookingID and DocTitle=l.InvoiceNumber and DocType=8)>0

解决方案 »

  1.   

    (select DocName from Document where BookingID=l.bookingID and DocTitle=l.InvoiceNumber and DocType=8) is not NULL
    錯誤不能這樣使用
    改寫;
    (select sum(1) from Document where BookingID=l.bookingID and DocTitle=l.InvoiceNumber and DocType=8)>0
      

  2.   

    Select L.BookingID,InvoiceNumber,b.Operator  from 
    view_bookingCOSTgroup L   join bookings_new b  
    on l.BookingID=b.BookingID  
    where ReceivePayTime is NULL and (select distinct DocName from Document where BookingID=l.bookingID and DocTitle=l.InvoiceNumber and DocType=8) is not NULL
      

  3.   

    問題的關鍵是子查詢中不能包含多條記錄,
    因此你只要將多條記錄轉化為一條記錄就可以了
    我剛才沒看清楚.Rotaxe(程序员)寫的非常好
      

  4.   

    这条语句有错,查询不唯一,可以使用 exists(select DocName from Document where BookingID=l.bookingID and DocTitle=l.InvoiceNumber and DocType=8) 即可.