日期:2014-05-17  浏览次数:20378 次

早起脑袋发懵。求一SQL。
单据号   付款别
 单据1    付款别1
 单据1    付款别2
 单据1    付款别3
 单据2    付款别1
 单据2    付款别3
 单据3    付款别1
 单据3    付款别4
 单据3    付款别5

一张单据可以使用不用付款别合并付款,想求使用付款别1但是不包含付款别3的单据号。。。

------解决方案--------------------
select distinct 单据号
from tab a
where 付款别= '付款别1'
and not exists (
select 1
from tab
where 单据号 = a.单据号
and 付款别= '付款别3'
)

------解决方案--------------------
写掉条件了 SORRY

select 单据号 from tb t where 付款别= '付款别1' and not exists (select 1 from tb where 单据号 = t.单据号 and 付款别= '付款别3')