sql - 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
解决方案
我想你想要or
:
where id = 1 or
(id = 2 and date between '2019-03-01' and '2019-04-01')
推荐阅读
- c - 对角线而不是左侧打印字符串
- node.js - 安装一个对等的东西
- python - df.rename() - TypeError: 'Index' object is not callable
- reactjs - React fetch 到 Express API 不起作用,有什么提示吗?
- chart.js - 如何将次要/主要配置添加到 Ticks
- javascript - 移除多个产品时,购物车系统出现故障
- css - 预定义样式不会改变
- javascript - 全局更改默认超时或仅用于一个测试的好习惯是什么?摩卡
- javascript - Vue:从数组中删除第一个元素并对其进行迭代
- java - 如何使用 Spring Boot 和 Java 库在谷歌上创建操作