を使用してい
A B C D
-------------------------
3 THREE
3 P
3 P
3 P
3 P
5 FIVE
5 P
は、私は以下のクエリは結果が
with temp as
(
SELECT ISNULL(a, (SELECT TOP 1 a FROM abcd
WHERE a = t.b
AND a IS NOT NULL
ORDER BY d DESC)) as a , b,c,d
FROM abcd t
),
flag as
(
select a,b,c,d,case when c='PF' then 1 else 0 end as flag
from temp
where c is not null
)
select * from temp
where a in (select distinct a from flag where c <> 'PF'
and a not in (select a from flag where flag=1))
を設定しています下の表を作成したレコード
create table abcd (a integer, b integer, c varchar(10), d varchar(100));
insert into abcd values (1,null,null,'ONE');
insert into abcd values (null,1,'P',null);
insert into abcd values (null, 1,'PF',null);
insert into abcd values (2,null,null,'TWO')
insert into abcd values (null,2,'PF',null);
insert into abcd values (3,null,null,'THREE');
insert into abcd values (null,3,'P',null);
insert into abcd values (null,3,'P',null);
insert into abcd values (null,3,'P',null);
insert into abcd values (null,3,'P',null);
insert into abcd values (4,null,null,'FOUR');
insert into abcd values (null,4,'PF',null);
insert into abcd values (null,4,'PF',null);
insert into abcd values (5,null,null,'FIVE');
insert into abcd values (null,5,'P',null);
select * from abcd;
を挿入
これはSQLiteでは機能しません。 –
大丈夫、私に知らせてくれてありがとう...これはtsqlで書かれています – Aparna