У меня проблема, ниже моего кода
$data = client_conf::select('cont_id','default_cont_id')->where('client_id',$client_id)->first();
$cont_id = explode(',', $data->cont_id);
$res_ = "'".implode("','", $cont_id)."'";
$custom2 = DB::table('client_conf as a')->where('client_id',$client_id)
->select(DB::raw("
a.cont_id as id_list,
a.default_cont_id id_default,
(SELECT bank_fee_trans_inter FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_trans_inter,
(SELECT bank_fee_skn FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_skn,
(SELECT bank_fee_skn FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_rtgs,
(SELECT bank_fee_trans FROM payout_cont as t WHERE t.cont_id in ($res_) and t.bank_cd='$bank_cd') as fee_trans_same,
(SELECT cont_id FROM payout_cont as t WHERE t.cont_id in ($res_) and t.bank_cd='$bank_cd') as id_trans
"))
->first();
результат $ cont_id = AAA, BBB
Кто-нибудь может помочь упростить запрос?
так что я могу сделать один раз запросы, не нужно делать дважды. (сначала запрашивает cont_id, затем я сначала взрываю его, затем выполняю второй).
проблема в $ res_
Я уже пытаюсь использовать concat и replace,
пример попытки: concat('\'',replace(a.cont_id,',',"','"),'\'')
. но получить результат id_trans = null.
Если кто-то может помочь решить эту проблему, я очень благодарен.
последний ->first()
изменить на ->tosql()
SELECT a.cont_id AS id_list, a.default_cont_id id_default,
(SELECT bank_fee_trans_inter
FROM payout_cont AS t
WHERE t.cont_id = a.default_cont_id) AS fee_trans_inter,
(SELECT bank_fee_skn
FROM payout_cont AS t
WHERE t.cont_id = a.default_cont_id) AS fee_skn,
(SELECT bank_fee_skn
FROM payout_cont AS t
WHERE t.cont_id = a.default_cont_id) AS fee_rtgs,
(SELECT bank_fee_trans
FROM payout_cont AS t
WHERE t.cont_id IN ( 'AAAA', 'BBB' )
AND t.bank_cd = 'CENA') AS fee_trans_same,
(SELECT cont_id
FROM payout_cont AS t
WHERE t.cont_id IN ( 'AAAA', 'BBB' )
AND t.bank_cd = 'CENA') AS id_trans
FROM `client_conf` AS `a`
WHERE `client_id` = ?
Я уже нахожу решение, используя find_in_set.
ниже моего кода обновления
$custom2 = DB::table('client_conf as a')->where('client_id',$client_id)
->select(DB::raw("
a.cont_id as id_list,
a.default_cont_id id_default,
(SELECT bank_fee_trans_inter FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_trans_inter,
(SELECT bank_fee_skn FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_skn,
(SELECT bank_fee_rtgs FROM payout_cont as t WHERE t.cont_id=a.default_cont_id) as fee_rtgs,
(SELECT bank_fee_trans FROM payout_cont t,client_conf j WHERE FIND_IN_SET(t.cont_id,id_list) <> 0 and t.bank_cd='$bank_cd' group by t.bank_fee_trans) as fee_trans_same,
(SELECT t.cont_id FROM payout_cont t,client_conf j WHERE FIND_IN_SET(t.cont_id,id_list) <> 0 and t.bank_cd='$bank_cd' group by t.cont_id) as id_trans
"))
->first();