当前位置: 代码迷 >> Sql Server >> 早间脑袋发懵。求一SQL
  详细解决方案

早间脑袋发懵。求一SQL

热度:84   发布时间:2016-04-24 20:13:58.0
早起脑袋发懵。求一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')
  相关解决方案