27,581
社区成员
发帖
与我相关
我的任务
分享
FilePath Key1
A01-51656\51656\1961\09 2
A01-51656\51656\1961\08 2
A01-51656\51656\1961\07 2
A01-51656\51656\1961\06 2
A01-51656\51656\1961\03 2
A01-51656\51656\1961\02 2
A01-51656\51656\1961\01 2
A01-51656\51656\1960\12 2
A01-51656\51656\1960\11 2
A01-51656\51656\1960\10 2
A01-51656\51656\1960\09 2
A01-51656\51656\1960\08 2
A01-51656\51656\1960\07 2
A01-51656\51656\1960\06 2
A01-51656\51656\1960\05 2
A01-51656\51656\1960\04 2
A01-51656\51656\1962\06 2
A01-51656\51656\1962\05 2
A01-51656\51656\1962\04 2
A01-51656\51656\1962\03 2
A01-51656\51656\1962\02 1
A01-51656\51656\1962\01 1
A01-51656\51656\1961\12 1
A01-51656\51656\1961\11 1
A01-51656\51656\1961\10 2
select left(FilePath,20) as tt
from tWork
where left(FilePath,20) not in (select left(FilePath,20) from tWork where Key1 = 0 or Key1 = 1)
group by left(FilePath,20)
-- 如果保证12月都有
select LEFT(filepath,LEN(filepath)-3) as v from tb where key1=2
group by LEFT(filepath,LEN(filepath)-3),key1 having count(1)=12
--
select LEFT(x.filepath,LEN(x.filepath)-3) as v from tb x
where not exists(select 1 from tb where key1=1 and LEFT(x.filepath,LEN(x.filepath)-3)=LEFT(filepath,LEN(filepath)-3))
group by LEFT(x.filepath,LEN(x.filepath)-3),x.key1
思路:
select LEFT(FilePath,20)
from dbo.Test
where Key1=2
group by LEFT(FilePath,20)
having COUNT(1)=12
select left(FilePath,14)+ min(left(right(FilePath,7),4)) from tb where key1 = 2
group by left(FilePath,14),(left(right(FilePath,7),4))