我有一个id
s的列表:
select id from id where sid = 2403
上面只返回一个id
的列表.例如id = 401434786、401434787、401434788等.
当我在tval
表中运行其中一个id
时,我得到:
select * from tval where id = 401434786;
我得到:
id fid ts val
401434786 3765 2019-05-14 00:00:00.000 2019-11-18 00:00:00.000
401434786 3771 2019-11-18 00:00:00.000 2019-11-18 00:00:00.000
401434786 3782 2019-05-14 00:00:00.000 2019-11-18 00:00:00.000
我的目标是过滤id
的列表,只有fid = 3771
和fid = 3782
的val
是NOT相同的那些.
我有一个查询,它做:
select distinct t.id from tval t
where (select min(t1.val) from tval t1
where t1.id = t.id and t1.fid = 3771)
!=(select min(t1.val) from tval t1
where t1.id = t.id and t1.fid = 3782)
and id in (select id from id where sid = 2403);
然而,我想修改查询,或者写一个全新的查询,以过滤id
的列表,其中只有Month
或Year
是不同的,但如果Month
和Year
是相同的,但Day
是不同的,然后删除它.
在上面的查询中,它过滤id
,如果Month
和Year
相同,但Day
不同,它仍然将其包含在输出中,但我不希望这样.我只想要Month
和Year
不同的id
.
我希望上面的内容是有意义的,我真的很感激任何帮助!