查询channel表中tag为CK和tag为BAS的数据,获取这两条数据的ID。并更新algorithm表,当algorithm表中type包含A,B,C,G则设置algorithm表中channel_ids字段的值为channel表中tag为CK的ID。当algorithm表中type包含E,F则设置algorithm表中channel_ids字段的值为channel表中tag为BAS的ID的sql语句该怎写
时间: 2023-02-08 20:19:58 浏览: 84
在 channel 表中查询 tag 为 CK 和 tag 为 BAS 的数据,并获取这两条数据的 ID,可以使用如下 SQL 语句:
```
SELECT id FROM channel WHERE tag IN ('CK', 'BAS');
```
更新 algorithm 表,当 algorithm 表中 type 包含 A,B,C,G 时,设置 algorithm 表中 channel_ids 字段的值为 channel 表中 tag 为 CK 的 ID,当 algorithm 表中 type 包含 E,F 时,设置 algorithm 表中 channel_ids 字段的值为 channel 表中 tag 为 BAS 的 ID,可以使用如下 SQL 语句:
```
UPDATE algorithm
SET channel_ids =
(CASE
WHEN type LIKE '%A%' OR type LIKE '%B%' OR type LIKE '%C%' OR type LIKE '%G%'
THEN (SELECT id FROM channel WHERE tag = 'CK')
WHEN type LIKE '%E%' OR type LIKE '%F%'
THEN (SELECT id FROM channel WHERE tag = 'BAS')
ELSE channel_ids
END)
```
注意: 请根据实际表名,表结构进行修改.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![md](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)