Добрый день!
Ниже приведенный запрос не обновляется в excell, т.к. не хватает памяти а если и хвататет то слишком долго происходит обновление. Как можно упростить текущий запрос? буду признателен за помощь
SELECT
case
when orders.operator_comment LIKE '%#dostavleno%' THEN 'ДОСТАВЛЕН ТО'
when warehouse1.name = warehouse.name THEN 'ЛЕЖИТ НА ТТ'
ELSE 'НЕ ДОСТАВЛЕН'
end,
case when orders.delivery_method=1 or orders.delivery_method=4 THEN ''
when orders.delivery_method=2 THEN warehouse.name
ELSE 'Кто тут у нас?' end,
case
when orders.operator_comment LIKE '%#grandgotov%' and orders.operator_comment LIKE '%#megagotov%' THEN 'ОБА_ГОТОВЫ_АА'
when orders.operator_comment LIKE '%#astmelomangotov%' and orders.operator_comment LIKE '%#astmarwingotov%' THEN 'ОБА_ГОТОВЫ_АС'
when orders.operator_comment LIKE '%#damn%' THEN 'НЕТ_ТОВАРА'
when orders.operator_comment LIKE '%#grandgotov%' THEN 'ГРАНД_СОБРАЛ'
when orders.operator_comment LIKE '%#megagotov%' THEN 'МЕГА_СОБРАЛ'
when orders.operator_comment LIKE '%#astmelomangotov%' THEN 'АСТ_МЕГА_СОБРАЛ'
when orders.operator_comment LIKE '%##astmarwingotov%' THEN 'АСТ_МАРВИН_СОБРАЛ'
ELSE 'НЕГОТОВ'
end,
extract(year from orders.order_date) as year,
extract(month from orders.order_date) as month,
extract(hour from orders.order_date) as hour,
extract(week from orders.order_date) as week,
date(orders.order_date),
orders.order_id,
orders.customer_surname,
orders.points_spent,
orders.bonus_points,
orders.customer_name,
orders.customer_secondname,
orders.customer_phone,
orders.customer_mobile,
orders.customer_email,
orders.delivery_region,
orders.delivery_city,
orders.delivery_microdistrict,
orders.delivery_street,
orders.delivery_house,
orders.delivery_apartment,
orders.delivery_zip_code,
orders.delivery_comment,
orders.retail_outlet_name,
orders.retail_outlet_address,
orders.retail_outlet_phone,
orders.retail_outlet_email,
orders.retail_outlet_warehouse_token,
(orders.delivery_cost+orders.order_cost) as itog,
orders.ic,
orders.delivery_method_description,
orders.delivery_date,
orders.delivery_time_of_day,
orders.delivery_cost,
orders.order_cost,
orders.order_date,
shipment.warehouse_token,
item.name_eshop,
item.id_ax,
item.name_ax,
item.category,
item.price,
item.quantity,
delivery_methods.caption,
order_conditions.caption,
order_states.caption,
orders.responsible,
warehouse1.name,
warehouse.name,
payment_methods.caption,
action_journal_goods_item_shipment_state.action_comment
FROM
imm.orders
INNER JOIN imm.item ON (orders.order_id = item.order_id)
INNER JOIN dictionaries.delivery_methods ON (orders.delivery_method = delivery_methods.id)
INNER JOIN dictionaries.order_conditions ON (orders.order_condition = order_conditions.id)
INNER JOIN dictionaries.order_states ON (orders.order_state = order_states.id)
INNER JOIN dictionaries.payment_methods ON(orders.payment_method = payment_methods.id),
imm.shipment
LEFT JOIN imm.action_journal_goods_item_shipment_state j ON j.id=(select max(id) from imm.action_journal_goods_item_shipment_state where reference_id = shipment.id),
imm.warehouse warehouse1,
imm.warehouse,
imm.action_journal_goods_item_shipment_state
WHERE
item.id = shipment.order_goods_item_id AND
warehouse1.token = shipment.warehouse_token AND
warehouse.token = orders.retail_outlet_warehouse_token and
orders.order_date > '2015-11-16' and orders.delivery_comment like '%expressdelivery%'