是否需要根据条件插入while循环? [英] Do I need a while loop to insert based on conditions?

查看:75
本文介绍了是否需要根据条件插入while循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据以下条件在列中插入值.要插入的列的名称为project_renewal.

I want to insert values in a column based on the following conditions. Name of the column to be inserted is project_renewal.

如果project_code中存在小数,请在小数后插入数字.

If decimal exists in project_code, insert the numbers after decimals.

SELECT substring_index(project_code, '.', -1)
FROM projects where
project_code like '%.%'

如果没有小数,请输入0.

If no decimal, insert 0.

SELECT project_code
FROM projects where
project_code not like '%.%'

插入顺序必须与从project_code读取值的顺序相同.

Order of insert must be the same as the order of reading values from project_code.

推荐答案

 INSERT IGNORE INTO outtable (code)
 SELECT IF (project_code LIKE '%.%'
     , substring_index(project_code, '.', -1)
     , 0)
 FROM projects

这篇关于是否需要根据条件插入while循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆