Mysql选择并比较行值

时间:2017-09-14 08:54:45

标签: mysql sql

我一直坚持制作表达,因为我不知道如何制作正确的查询命令。

这是我想做的事情:

var path = require("path");
var WebpackShellPlugin = require('webpack-shell-plugin');

var config = {
    entry: ["./src/App.tsx"],

    output: {
        path: path.resolve(__dirname, "build"),
        filename: "bundle.js"
    },

    devtool: 'source-map',

    resolve: {
        extensions: [".ts", ".tsx", ".js"]
    },

    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "ts-loader",
                exclude: /node_modules/
            },
            {
            test: /\.scss$/,
                use: [{
                    loader: "style-loader" // creates style nodes from JS strings
                }, {
                    loader: "css-loader" // translates CSS into CommonJS
                }, {
                    loader: "sass-loader" // compiles Sass to CSS
                }]
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            }
        ]
    },

    plugins: [
        new WebpackShellPlugin({
            onBuildEnd:['./cp_to_static.sh'],
            dev: false  // Needed to trigger on npm run watch
        })
    ]
};

module.exports = config;

我想根据他们迟到的时间来评价他们,

如果他们的迟到等于或小于1他们将被认为是好的

如果他们的迟到等于或超过3他们将被视为不好

如果他们的迟到等于或超过4,他们将被视为非常糟糕

如何进行查询,得出如下结果:

Member Table 
member_id ----- member_name ----- late
1         ----- John        -----   0
2         ----- Doe         -----   4
3         ----- Dennis      -----   6


Type Table
type_id ----- type_name ----- ctr
1       -----  Good     -----  1
2       -----  Bad      -----  3
3       -----  Very Bad -----  5

2 个答案:

答案 0 :(得分:1)

你可以尝试这样的事情(你必须修改你的TYPE表,添加CTR_START和CTR_END):

CREATE TABLE MEMBER_TABLE (MEMBER_ID INT, MEMBER_NAME VARCHAR(20), LATE INT)
INSERT INTO MEMBER_TABLE VALUES (1,'John', 0);
INSERT INTO MEMBER_TABLE VALUES (2,'Doe', 4);
INSERT INTO MEMBER_TABLE VALUES (3,'Dennis', 6);

CREATE TABLE TYPE_TABLE (TYPE_ID INT, TYPE_NAME VARCHAR(20), CTR_START INT, CTR_END INT)
INSERT INTO TYPE_TABLE VALUES (1,'Good', 0,2);
INSERT INTO TYPE_TABLE VALUES (2,'Bad', 3,4);
INSERT INTO TYPE_TABLE VALUES (3,'Very Bad', 5,999);


SELECT A.MEMBER_NAME, B.TYPE_NAME
FROM MEMBER_TABLE A
LEFT JOIN TYPE_TABLE B ON A.late>= B.CTR_START AND A.LATE<=B.CTR_END;

输出:

MEMBER_NAME TYPE_NAME
John    Good
Doe     Bad
Dennis  Very Bad

答案 1 :(得分:0)

我不确定我是否理解正确但是:

SELECT m.member_name, t.type_name
FROM members m JOIN types t ON m.late = t.type_id