使用大于和小于函数编写SQL代码

时间:2018-11-08 23:41:37

标签: mysql sql tsql

当我尝试运行此代码时:

    import json
import itertools
import os

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import tensorflow as tf

from sklearn.preprocessing import LabelBinarizer, LabelEncoder
from sklearn.metrics import confusion_matrix

    from tensorflow import keras
    from keras.models import Sequential
    from keras.layers import Dense, Activation, Dropout
    from keras.preprocessing import text, sequence
    from keras import utils

    # The CSV was generated from this query: 
    data = pd.read_csv("data.csv")
    data.head()

    # Confirm that we have a balanced dataset
    # Note: data was randomly shuffled in our BigQuery query
    data['tags'].value_counts()

    # Split data into train and test
    train_size = int(len(data) * .8)
    print ("Train size: %d" % train_size)
    print ("Test size: %d" % (len(data) - train_size))

    train_posts = data['post'][:train_size]
    train_tags = data['tags'][:train_size]


    test_posts = data['post'][train_size:]
    test_tags = data['tags'][train_size:]

    max_words = 1000
    tokenize = text.Tokenizer(num_words=max_words, char_level=False)

    tokenize.fit_on_texts(train_posts) # only fit on train
    x_train = tokenize.texts_to_matrix(train_posts)
    x_test = tokenize.texts_to_matrix(test_posts)

    dictionary = tokenize.word_index
    with open('dictionary.json', 'w') as dictionary_file:
        json.dump(dictionary, dictionary_file)


    # Use sklearn utility to convert label strings to numbered index
    encoder = LabelEncoder()
    encoder.fit(train_tags.fillna('0'))

    y_train = encoder.transform(train_tags.fillna('0'))
    y_test = encoder.transform(test_tags.fillna('0'))

    # Converts the labels to a one-hot representation
    num_classes = np.max(y_train) + 1
    y_train = utils.to_categorical(y_train, num_classes)
    y_test = utils.to_categorical(y_test, num_classes)

我收到一条错误消息,提示“>附近的语法不正确”,并带我到第一个有>的实例。然后,当我徘徊时,第一次收到错误消息时,它还提到了“布尔函数”。

我希望这段代码根据上述条件为我返回颜色值。

3 个答案:

答案 0 :(得分:0)

ã仅接受一个参数,并在MySQL中返回1或0。您可能正在寻找ISNULL。 另外,将0用作NULL替换也是一个坏主意,因为您将被0除。

答案 1 :(得分:0)

我猜您希望标准的ACR = 0xf00000 函数能够防止被零除。此版本的查询应该可以工作:

NULLIF()

我没有发现您的查询明显有问题。一种可能性是该位置周围的性格不好。有时只需重新输入代码即可解决问题。

答案 2 :(得分:0)

将ISNULL更改为IFNULL:

Set @promotionflag=-1;
set @Margin = 4.0000;
set @Sales = 3;
set @Funding = 4;
SELECT 
CASE WHEN @promotionflag=0 THEN 'NoPromotion' 
WHEN (@Sales)/(IFNULL(@Margin,0)) > -3.0000 AND (@Sales)/(IFNULL(@Funding, 0)) < 0 THEN 'RED'
WHEN (@Sales) <0 THEN 'RED'
WHEN (@Sales)= 0 and (@Margin) <0 then 'RED'
WHEN (@Sales)/(IFNULL(@Margin, 0)) >= 0 THEN 'GREEN'
WHEN (@Sales) IS NULL THEN 'NonPriority'
WHEN (@Margin) IS NULL THEN 'NonPriority'
ELSE 'YELLOW' 
END AS Promotions