SQL错误:有操作

时间:2016-11-30 09:40:23

标签: sql postgresql

我需要编写一个sql脚本,它必须显示所有人类客户端,其最大收入是最大收入的两倍。

@Override
public boolean onTouchEvent(MotionEvent event) {
    return gameThread.doOnTouch(event);
}


public boolean doOnTouch(MotionEvent event){

    synchronized (event){

        int eventAction = event.getAction();
        int xEvent = (int)event.getX();
        int yEvent = (int)event.getY();

        switch (eventAction){

            case MotionEvent.ACTION_DOWN:

                        if(xEvent >= rectangle.getLeft() && xEvent <= rectangle.getRight()
                                && yEvent >= rectangle.getBottom() && yEvent<= rectangle.getTop())
                        {
                            touched = true;
                            score +=5;
                        }
                }
                break;
            case MotionEvent.ACTION_UP:
                touched = false;
                break;
        }
        return true;
    }
}

apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.1" defaultConfig { applicationId "com.example.jignesh.myapplication" minSdkVersion 25 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.0', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.0.1' testCompile 'junit:junit:4.12' } - 用于按男人的中间名(俄语要求)对男性进行分类

表格如下:

enter image description here

A收到这样的错误:

  

错误:列“income_ratio”不存在(第6行)

我做错了什么?

3 个答案:

答案 0 :(得分:2)

而不是income_ratio将子句写为max(monthly_income_amt) / min(monthly_income_amt)>2

在您分组时,distinct也没有意义。

答案 1 :(得分:1)

需要修改您的having子句,如下所示。

SELECT
      DISTINCT
      customer_rk,
      max(monthly_income_amt),
      min(monthly_income_amt),
      max(monthly_income_amt) / min(monthly_income_amt) AS income_ratio
    FROM asql.individual_customer
    WHERE middle_nm LIKE '%ВИЧ'
    GROUP BY customer_rk
    HAVING (max(monthly_income_amt) / min(monthly_income_amt)) > 2

答案 2 :(得分:0)

将查询包装在派生表中。然后你可以将income_ratio放在WHERE子句中:

select * from
(
    SELECT
      customer_rk,
      max(monthly_income_amt),
      min(monthly_income_amt),
      max(monthly_income_amt) / min(monthly_income_amt) AS income_ratio
    FROM asql.individual_customer
    WHERE middle_nm LIKE '%ВИЧ'
    GROUP BY customer_rk
) dt
where income__ratio > 2;