1

[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
4

2 回答 2

3

我想你想要or

where id = 1 or
      (id = 2 and date between '2019-03-01' and '2019-04-01')
于 2019-08-02T18:29:15.057 回答
0

对于您想要的结果需要

select * from table1 where  [date] >= '2019-01-01' and [date] <= '2019-03-01'
于 2019-08-02T18:27:20.480 回答