SELECT
val.*,
val_sale.sale,
ANY_VALUE(bi.id_name_banks) buy_bank,
ANY_VALUE(si.id_name_banks) sale_bank,
val_cbrf.value
FROM
(
SELECT MAX(value)
buy,
id_name_currency
FROM
parser_all_exchange_rates
WHERE
date = CURRENT_DATE() AND
id_name_banks != 233
GROUP BY
id_name_currency
) val,
(
SELECT
MIN(value_sale) sale,
id_name_currency
FROM
parser_all_exchange_rates
WHERE
date = CURRENT_DATE() AND
value_sale > 0 AND
id_name_banks != 233
GROUP BY
id_name_currency
) val_sale,
(
SELECT
r.value,
r.id_name_currency
FROM
parser_all_exchange_rates r
WHERE
r.id_name_banks = 233 AND
r.date = CURRENT_DATE()
) val_cbrf,
parser_all_exchange_rates bi,
parser_all_exchange_rates si
WHERE
bi.id_name_currency = val.id_name_currency AND
val.buy = bi.value AND
val_sale.id_name_currency = val.id_name_currency AND
bi.date = CURRENT_DATE() AND
si.id_name_currency = val.id_name_currency AND
val_sale.sale = si.value_sale AND
si.date = CURRENT_DATE() AND
val_cbrf.id_name_currency = val.id_name_currency
GROUP BY
val.id_name_currency,
val.buy,
val_sale.sale,
val_cbrf.value