Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何编写excludes if exists查询_Sql - Fatal编程技术网

Sql 如何编写excludes if exists查询

Sql 如何编写excludes if exists查询,sql,Sql,我需要写一个查询来展示访问过我网站的用户,除非他们在2008年访问过我的网站 因此,如果他们在2008年访问,我不希望他们成为图表的一部分,即使他们在不同的年份访问 如果用户在2008年访问过,我如何编写一个排除表中所有用户活动和数据的查询 我有 唯一用户名 用户ID 日期一种方法不存在: 另一种方法是: 选择不同的用户 从t 除了 选择用户 从t 其中日期介于“2008-01-01”和“2009-01-01”之间 还有一种方法是使用分析功能: select ... from ( select

我需要写一个查询来展示访问过我网站的用户,除非他们在2008年访问过我的网站

因此,如果他们在2008年访问,我不希望他们成为图表的一部分,即使他们在不同的年份访问

如果用户在2008年访问过,我如何编写一个排除表中所有用户活动和数据的查询

我有

唯一用户名 用户ID 日期

一种方法不存在:

另一种方法是:

选择不同的用户 从t 除了 选择用户 从t 其中日期介于“2008-01-01”和“2009-01-01”之间
还有一种方法是使用分析功能:

select ...
from 
(
select t.*, sum(case when date between '2008-01-01' and '2008-12-31' then 1 else 0 end) over (partition by userid) as cnt_2008
  from t
) s
where s.cnt_2008 = 0

哪一个是数据库?所以我加入了我的表没有以下列的地方:唯一用户名Mike Smith用户ID 12345日期2008-01-01如果数据来自2005-2015,我想显示所有信息,除了包括Mike Smith在内的所有信息,因为他在2008年访问过。因为他有一次访问过,我想把他在其他年份的访问也排除在外。那么这个查询是否会排除在2008年访问过的用户,以及用户ID分配到的任何其他数据,并显示表中的所有其他内容?@Andrewsarazin。这将删除2008年期间任何时候拥有记录的所有用户。
select ...
from 
(
select t.*, sum(case when date between '2008-01-01' and '2008-12-31' then 1 else 0 end) over (partition by userid) as cnt_2008
  from t
) s
where s.cnt_2008 = 0