MySQL Forums
Forum List  »  Newbie

How to traverse the rows of table, when a field meets condition then insert certain field value?
Posted by: mark leo
Date: November 25, 2021 07:04AM

How to traverse the rows of table, when a field meets condition then insert certain field value?
I have data like below:

```
id domain cname keyword
1 www.demo1.com demo1.com.dns1.com
2 www.demo2.com demo2.com.dns1.com
3 www.demo3.com demo3.com.dns.com
4 www.demo4.com demo4.com.cds1.com
5 www.demo5.com demo5.com.dns3.com
6 www.demo6.com demo6.com.dns4.com
7 www.demo7.com demo7.com.dns4.com
8 www.demo8.com demo8.com.dns4.com
....
```

I want to insert a column, when meet conditions:
if `cname` have string in `[ 'dns1', 'dns2' ]`, then add the field `keyword` = `dns1`.
if `cname` have string in `[ 'dns3', 'cds1' ]`, then add the field `keyword` = `dns2`.
if `cname` have string in `[ 'dns4' ]`, then add the field `keyword` = `NULL`.

how to implement it?

Options: ReplyQuote


Subject
Written By
Posted
How to traverse the rows of table, when a field meets condition then insert certain field value?
November 25, 2021 07:04AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.