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

怎么写这个逻辑复杂的sql?
表结构如下:

销售单号   负责部门   状态
1          车间       生产中
1          库房       待售
1          销售部     售出
2          销售部     售出
3          车间       生产中


怎么写个查询能找到所有销售单号中,已卖出的,而且只经过销售部(就是说商品没进入车间和库房的)?

------解决方案--------------------
select * from table t where t.depart_nm='销售部' and t.status='售出' and t.sale_id not in (select sale_id from table t where t.depart_nm<>'销售部' and t.status='售出')