0

我有一个包含几列的表,但想从一个特定列(销售编号)中提取数据。

销售编号 列由一组由 [-] 分隔的数字组成,即401001-402001-403001-404001

当进行销售时,401001输入所有四个中的一个或组合。我试图拉的只是(402001404001)组合的销售;401001单身;402001作为两倍。请参阅以下查询。先感谢您!!!!

select 
     sum(case 
             when (salesno like '402001' and salesno like '%404001%') then 1 else 0 
         end) as [combo]
from 
     table1
where 
    (salesno like '%402001%' and salesno like '%404001%')
    and (salesno not like '%401001%')
    and (salesno not like '%402001%')
    and (salesno not like '%403001%')
    and (salesno not like '%404001%')
    and saledate between '10/01/2013' and '10/31/2013'
group by
    (case when (salesno like '402001' or salesno like '%404001%') 
4

0 回答 0