当前位置:贵波网 > 内容 > 正文

Sql Server中 Not In 替换 Not exists 或left join

2021-06-24 15

select COUNT(*)
from table1
where
[date]>getdate()
and [date]<(getdate()+1)

AND NOT EXISTS (
SELECT 1
FROM table2
WHERE
table1.id = table2.id
AND table2.[date]>getdate()
and table2.[date]<(getdate()+1)
AND table2.IsTrue=1

)试试用这个
select COUNT(1) from table1 a inner join table2 b on a.id=b.id where [a.date]>getdate() and [a.date]<(getdate()+1) and b.IsTrue=1
本周热门
热门文章
热门关注