In the first code just below, I can list right the freight price of the transports table via the range of cep
and peso
, however I'm having a problem, I need to sort the result according to zip sent, depending on the query is falling on the second line and needs to be in the first line, I am not sure how to use the CASE
function along with BETWEEN
to return it to the first position afterwards in the ORDER BY
This works fine, without CASE
SELECT
'Transportadora'.*,
FROM 'envio_transportadora' AS 'Transportadora'
INNER JOIN 'shop_envio' AS 'ShopEnvio'
ON ('ShopEnvio'.'id_envio' = 'Transportadora'.'id_envio_default' AND 'ShopEnvio'.'ativo' = 'True' AND 'ShopEnvio'.'id_shop_default' = '5')
WHERE
'78000-000' BETWEEN 'Transportadora'.'cep_inicio' AND 'Transportadora'.'cep_fim' AND 13 BETWEEN 'Transportadora'.'peso_inicial' AND 'Transportadora'.'peso_final'
Already with CASE
of syntax error in query
below:
SELECT
'Transportadora'.*,
((CASE WHEN '78000-000' BETWEEN 'Transportadora'.'cep_inicio' AND 'Transportadora'.'cep_fim')) AS cep_ordenar
FROM 'envio_transportadora' AS 'Transportadora'
INNER JOIN 'shop_envio' AS 'ShopEnvio'
ON ('ShopEnvio'.'id_envio' = 'Transportadora'.'id_envio_default' AND 'ShopEnvio'.'ativo' = 'True' AND 'ShopEnvio'.'id_shop_default' = '5')
WHERE
'78000-000' BETWEEN 'Transportadora'.'cep_inicio' AND 'Transportadora'.'cep_fim' AND 13 BETWEEN 'Transportadora'.'peso_inicial' AND 'Transportadora'.'peso_final'