是否需要根据条件插入while循环?

时间:2020-02-05 19:42:50

标签: mysql sql if-statement

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

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

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

如果没有小数,则输入0。

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

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

2 个答案:

答案 0 :(得分:1)

from tensorflow.keras.preprocessing.image import ImageDataGenerator
import tensorflow as tf

train_path = 'Skin/Train'
test_path = 'Skin/Test'

train_gen = ImageDataGenerator(rescale=1./255)
train_generator = train_gen.flow_from_directory(train_path,target_size= 
                                         (300,300),batch_size=30,class_mode='categorical')

model = tf.keras.models.Sequential([
# Note the input shape is the desired size of the image 300x300 with 3 bytes color
# This is the first convolution
tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(600, 450, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
# The second convolution
tf.keras.layers.Conv2D(32, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# The third convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# The fourth convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# The fifth convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
# Flatten the results to feed into a DNN
tf.keras.layers.Flatten(),
# 512 neuron hidden layer
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(9, activation='softmax')
])

from tensorflow.keras.optimizers import RMSprop

model.compile(loss='categorical_crossentropy',
          optimizer=RMSprop(lr=0.001),
          metrics=['acc'])

history = model.fit_generator(
  train_generator,
  steps_per_epoch=8,  
  epochs=15,
  verbose=2, class_weight = ? )

答案 1 :(得分:0)

您可以这样做:

INSERT INTO tablename(project_renewal)
SELECT trim(trailing '0' from substring_index(project_code, '.', -1)) + 0
FROM projects

请参见demo

如果要更新同一表中的列,请执行UPDATE语句:

UPDATE projects
SET project_renewal = trim(trailing '0' from substring_index(project_code, '.', -1)) + 0

请参见demo