首页 > 解决方案 > How to filter only a subset of data while maintain existing records as is in a table?

问题描述

[SQL Novice] I have a table that looks like this:

id             date
1              2019-01-01
1              2019-01-02
2              2019-03-01
2              2019-05-01

I want to only filter the id column on 2 where date is between 2019-04-01 and 2019-05-01 without impacting id equals 1.

The new table should look like this:

id             date
1              2019-01-01
1              2019-01-02
2              2019-03-01

I tried this:

select * from table1 where id =2 and date between 2019-03-01 and 2019-04-01

And get this data set:

id             date

2              2019-03-01

标签: sqlsql-serverdremio

解决方案


我想你想要or

where id = 1 or
      (id = 2 and date between '2019-03-01' and '2019-04-01')

推荐阅读