2016-04-18 28 views
0

私はmysqlクエリでエラーが発生しているので、前の選択値に基づいてifステートメントが必要です。ここselectステートメントのCASE mysql

は私のクエリです

SELECT 
    ds.master_rcpt_gen, 
    ds.visa_rcpt_gen, 
    dsp.curr_amount, 
    dsp.curr_id, 
    mcr.conv_rate, 
    mcr.curr_code, 
    mcr.curr_desc, 
    mcr.curr_type, 
    (conv_rate/(select mcr.conv_rate from mst_currencies_rate mcr where mcr.curr_code = 'USD')) conv_ratio, 
    curr_amount * (conv_rate/(select mcr.conv_rate from mst_currencies_rate mcr where mcr.curr_code = 'USD')) conv_usd, 
    (select mtr.USD_tax_rate from mst_tax_rate mtr) * (curr_amount * (conv_rate/(select mcr.conv_rate from mst_currencies_rate mcr where mcr.curr_code = 'USD'))) AS conv_taxrate_commission, 
    CASE WHEN mcr.curr_type = 'LOCAL' THEN conv_taxrate_commission = dsp.curr_amount ELSE (select mtr.USD_tax_rate from mst_tax_rate mtr) * (curr_amount * (conv_rate/(select mcr.conv_rate from mst_currencies_rate mcr where mcr.curr_code = 'USD'))) 
    END final_conv_rate 
FROM 
    dtl_sr ds 
INNER JOIN dtl_sr_payment dsp ON dsp.flight_id = ds.flight_id 
AND dsp.sr_id = ds.SR_ID 
INNER JOIN mst_currencies_rate mcr ON mcr.curr_id = dsp.curr_id 

私のエラーはcase文で起こった、私はconv_taxrate_commissionから値を読み取るためにcase文を必要としています。 IF mcr.curr_type = 'LOCAL'私はconv_taxrate_commissionをdsp.curr_amountと等しくする必要があります。そうでなければ、conv_taxrate_commissionをそのままにしておく必要があります。

+1

あなたが取得しているどのようなエラー? –

+0

エラー1054不明な列 'field_list'の 'conv_taxrate_commission' –

+1

なぜ 'CASE'式の' THEN'の後に 'conv_taxrate_commission = dsp.curr_amount'が必要なのですか? – Wanderer

答えて

1

final_conv_ratedsp.curr_amountで、ときmcr.curr_type = 'LOCAL' 私は仮定し、これを試してみてください、私を助けてください;)

SELECT 
    ds.master_rcpt_gen, 
    ds.visa_rcpt_gen, 
    dsp.curr_amount, 
    dsp.curr_id, 
    mcr.conv_rate, 
    mcr.curr_code, 
    mcr.curr_desc, 
    mcr.curr_type, 
    (conv_rate/(SELECT mcr.conv_rate 
       FROM mst_currencies_rate mcr 
       WHERE mcr.curr_code = 'USD'))             conv_ratio, 
    curr_amount * (conv_rate/(SELECT mcr.conv_rate 
           FROM mst_currencies_rate mcr 
           WHERE mcr.curr_code = 'USD'))         conv_usd, 
    CASE WHEN mcr.curr_type = 'LOCAL' 
    THEN dsp.curr_amount 
    ELSE 
    (SELECT mtr.USD_tax_rate 
    FROM mst_tax_rate mtr) * (curr_amount * (conv_rate/(SELECT mcr.conv_rate 
                  FROM mst_currencies_rate mcr 
                  WHERE mcr.curr_code = 'USD'))) END conv_taxrate_commission, 
    CASE WHEN mcr.curr_type = 'LOCAL' 
    THEN dsp.curr_amount 
    ELSE (SELECT mtr.USD_tax_rate 
     FROM mst_tax_rate mtr) * (curr_amount * (conv_rate/(SELECT mcr.conv_rate 
                   FROM mst_currencies_rate mcr 
                   WHERE mcr.curr_code = 'USD'))) 
    END                       final_conv_rate 
FROM 
    dtl_sr ds 
    INNER JOIN dtl_sr_payment dsp ON dsp.flight_id = ds.flight_id 
            AND dsp.sr_id = ds.SR_ID 
    INNER JOIN mst_currencies_rate mcr ON mcr.curr_id = dsp.curr_id 
+0

ありがとう、somuch、そのawesoe –