将SQL IIF转换为Redshift

时间:2018-09-06 15:00:41

标签: sql sql-server amazon-redshift

我有sql server脚本,需要将其转换为Redshift

这是我遇到问题的代码的一部分

`z_ =tf.placeholder(tf.float32, [None])
z1 = z_
y_conv=tf.nn.softmax(logits)
#training_loop
for i in range(FLAGS.training_step):`
    batch = data_sets.train.next_batch(FLAGS.batch_size)
    optimizer.run(feed_dict = {x: batch[0], y_: batch[1]})
    if(i%100 ==0):
        train_accuracy = accuracy.eval(feed_dict= {x: batch[0], y_: 
        batch[1]})
        test_accuracy = y_conv.eval(feed_dict= {x: 
        data_sets.test.MC_Samples})
        x_test_label= z1.eval(feed_dict= {z_:data_sets.test.labels})
        print("print_result")  
        print(x_test_label)
        print(test_accuracy)`

如何将其正确转换为Redshift?

1 个答案:

答案 0 :(得分:5)

IIF只是CASE表达式的语法糖(此行为在文档中已提及)。您的代码与以下代码相同:

CASE WHEN smf.channelid IS NULL THEN 0 ELSE 1 END AS IsFeatureKey,
CASE WHEN codeLabel.CslId > 0 THEN 1 ELSE 0 END AS IsCslCode,
CASE WHEN codeLabel.LearnId > 0 THEN 1 ELSE 0 END AS IsLearnCode,
CASE WHEN codeLabel.PMId > 0 THEN 1 ELSE 0 END AS IsPMCode,
CASE WHEN codeLabel.UpSell > 0 THEN 1 ELSE 0 END AS IsUpSell